github.com/AbhinandanKurakure/podman/v3@v3.4.10/libpod/lock/shm/shm_lock_nocgo.go (about)

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