def acquire(self, hostId): with nested(self._lock, SANLock._sanlock_lock): self.log.info("Acquiring cluster lock for domain %s (id: %s)", self._sdUUID, hostId) while True: if SANLock._sanlock_fd is None: try: SANLock._sanlock_fd = sanlock.register() except sanlock.SanlockException as e: raise se.AcquireLockFailure( self._sdUUID, e.errno, "Cannot register to sanlock", str(e)) try: sanlock.acquire(self._sdUUID, SDM_LEASE_NAME, [(self._leasesPath, SDM_LEASE_OFFSET)], slkfd=SANLock._sanlock_fd) except sanlock.SanlockException as e: if e.errno != os.errno.EPIPE: raise se.AcquireLockFailure( self._sdUUID, e.errno, "Cannot acquire cluster lock", str(e)) SANLock._sanlock_fd = None continue break self.log.debug( "Cluster lock for domain %s successfully acquired " "(id: %s)", self._sdUUID, hostId)
def acquire(self, hostID): leaseTimeMs = self._leaseTimeSec * 1000 ioOpTimeoutMs = self._ioOpTimeoutSec * 1000 with self._lock: self.log.debug("Acquiring cluster lock for domain %s" % self._sdUUID) lockUtil = self.getLockUtilFullPath() acquireLockCommand = subprocess.list2cmdline([ lockUtil, "start", self._sdUUID, str(hostID), str(self._lockRenewalIntervalSec), str(self._leasesPath), str(leaseTimeMs), str(ioOpTimeoutMs), str(self._leaseFailRetry) ]) cmd = [ constants.EXT_SU, misc.IOUSER, '-s', constants.EXT_SH, '-c', acquireLockCommand ] (rc, out, err) = misc.execCmd(cmd, cwd=self.lockUtilPath, sudo=True, ioclass=utils.IOCLASS.REALTIME, ioclassdata=0, setsid=True) if rc != 0: raise se.AcquireLockFailure(self._sdUUID, rc, out, err) self.log.debug("Clustered lock acquired successfully")
def acquire(self, hostID): leaseTimeMs = self._leaseTimeSec * 1000 ioOpTimeoutMs = self._ioOpTimeoutSec * 1000 with self._lock: self.log.debug("Acquiring cluster lock for domain %s" % self._sdUUID) lockUtil = os.path.join(self.lockUtilPath, self.lockCmd) acquireLockCommand = subprocess.list2cmdline([ lockUtil, "start", self._sdUUID, str(hostID), str(self._lockRenewalIntervalSec), str(self._leaseFile), str(leaseTimeMs), str(ioOpTimeoutMs), str(self._leaseFailRetry) ]) cmd = [ constants.EXT_SETSID, constants.EXT_IONICE, '-c1', '-n0', constants.EXT_SU, misc.IOUSER, '-s', constants.EXT_SH, '-c', acquireLockCommand ] (rc, out, err) = misc.execCmd(cmd, cwd=self.lockUtilPath) if rc != 0: raise se.AcquireLockFailure(self._sdUUID, rc, out, err) self.__hostID = hostID self.log.debug("Clustered lock acquired successfully")
def acquire(self, hostId): with self._globalLockMapSync: self.log.info("Acquiring local lock for domain %s (id: %s)", self._sdUUID, hostId) lockFile = self._globalLockMap.get(self._sdUUID, None) if lockFile: try: misc.NoIntrCall(fcntl.fcntl, lockFile, fcntl.F_GETFD) except IOError as e: # We found a stale file descriptor, removing. del self._globalLockMap[self._sdUUID] # Raise any other unkown error. if e.errno != os.errno.EBADF: raise else: self.log.debug( "Local lock already acquired for domain " "%s (id: %s)", self._sdUUID, hostId) return # success, the lock was already acquired lockFile = misc.NoIntrCall(os.open, self._idsPath, os.O_RDONLY) try: misc.NoIntrCall(fcntl.flock, lockFile, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError as e: misc.NoIntrCall(os.close, lockFile) if e.errno in (os.errno.EACCES, os.errno.EAGAIN): raise se.AcquireLockFailure(self._sdUUID, e.errno, "Cannot acquire local lock", str(e)) raise else: self._globalLockMap[self._sdUUID] = lockFile self.log.debug( "Local lock for domain %s successfully acquired " "(id: %s)", self._sdUUID, hostId)