github.com/containers/podman/v4@v4.9.4/libpod/lock/shm/shm_lock_nocgo.go (about) 1 //go:build linux && !cgo 2 // +build linux,!cgo 3 4 package shm 5 6 import ( 7 "github.com/sirupsen/logrus" 8 ) 9 10 // SHMLocks is a struct enabling POSIX semaphore locking in a shared memory 11 // segment. 12 type SHMLocks struct { 13 } 14 15 // CreateSHMLock sets up a shared-memory segment holding a given number of POSIX 16 // semaphores, and returns a struct that can be used to operate on those locks. 17 // numLocks must not be 0, and may be rounded up to a multiple of the bitmap 18 // size used by the underlying implementation. 19 func CreateSHMLock(path string, numLocks uint32) (*SHMLocks, error) { 20 logrus.Error("Locks are not supported without cgo") 21 return &SHMLocks{}, nil 22 } 23 24 // OpenSHMLock opens an existing shared-memory segment holding a given number of 25 // POSIX semaphores. numLocks must match the number of locks the shared memory 26 // segment was created with. 27 func OpenSHMLock(path string, numLocks uint32) (*SHMLocks, error) { 28 logrus.Error("Locks are not supported without cgo") 29 return &SHMLocks{}, nil 30 } 31 32 // GetMaxLocks returns the maximum number of locks in the SHM 33 func (locks *SHMLocks) GetMaxLocks() uint32 { 34 logrus.Error("Locks are not supported without cgo") 35 return 0 36 } 37 38 // Close closes an existing shared-memory segment. 39 // The segment will be rendered unusable after closing. 40 // WARNING: If you Close() while there are still locks locked, these locks may 41 // fail to release, causing a program freeze. 42 // Close() is only intended to be used while testing the locks. 43 func (locks *SHMLocks) Close() error { 44 logrus.Error("Locks are not supported without cgo") 45 return nil 46 } 47 48 // AllocateSemaphore allocates a semaphore from a shared-memory segment for use 49 // by a container or pod. 50 // Returns the index of the semaphore that was allocated. 51 // Allocations past the maximum number of locks given when the SHM segment was 52 // created will result in an error, and no semaphore will be allocated. 53 func (locks *SHMLocks) AllocateSemaphore() (uint32, error) { 54 logrus.Error("Locks are not supported without cgo") 55 return 0, nil 56 } 57 58 // AllocateGivenSemaphore allocates the given semaphore from the shared-memory 59 // segment for use by a container or pod. 60 // If the semaphore is already in use or the index is invalid an error will be 61 // returned. 62 func (locks *SHMLocks) AllocateGivenSemaphore(sem uint32) error { 63 logrus.Error("Locks are not supported without cgo") 64 return nil 65 } 66 67 // DeallocateSemaphore frees a semaphore in a shared-memory segment so it can be 68 // reallocated to another container or pod. 69 // The given semaphore must be already allocated, or an error will be returned. 70 func (locks *SHMLocks) DeallocateSemaphore(sem uint32) error { 71 logrus.Error("Locks are not supported without cgo") 72 return nil 73 } 74 75 // DeallocateAllSemaphores frees all semaphores so they can be reallocated to 76 // other containers and pods. 77 func (locks *SHMLocks) DeallocateAllSemaphores() error { 78 logrus.Error("Locks are not supported without cgo") 79 return nil 80 } 81 82 // LockSemaphore locks the given semaphore. 83 // If the semaphore is already locked, LockSemaphore will block until the lock 84 // can be acquired. 85 // There is no requirement that the given semaphore be allocated. 86 // This ensures that attempts to lock a container after it has been deleted, 87 // but before the caller has queried the database to determine this, will 88 // succeed. 89 func (locks *SHMLocks) LockSemaphore(sem uint32) error { 90 logrus.Error("Locks are not supported without cgo") 91 return nil 92 } 93 94 // UnlockSemaphore unlocks the given semaphore. 95 // Unlocking a semaphore that is already unlocked with return EBUSY. 96 // There is no requirement that the given semaphore be allocated. 97 // This ensures that attempts to lock a container after it has been deleted, 98 // but before the caller has queried the database to determine this, will 99 // succeed. 100 func (locks *SHMLocks) UnlockSemaphore(sem uint32) error { 101 logrus.Error("Locks are not supported without cgo") 102 return nil 103 } 104 105 // GetFreeLocks gets the number of locks available to be allocated. 106 func (locks *SHMLocks) GetFreeLocks() (uint32, error) { 107 logrus.Error("Locks are not supported without cgo") 108 return 0, nil 109 } 110 111 // Get a list of locks that are currently taken. 112 func (locks *SHMLocks) GetTakenLocks() ([]uint32, error) { 113 logrus.Error("Locks are not supported without cgo") 114 return nil, nil 115 }