Beispiel #1
0
 def wakeup(self):
     try:
         utils.NoIntrCall(os.write, self._wfd, b"\0")
     except OSError as e:
         if self.closing:
             # Another thread tried to wake up after loop was closed.
             return
         if e.errno == errno.EAGAIN:
             # The pipe is full, no need to write.
             return
         raise
Beispiel #2
0
    def acquire(self, hostId):
        with self._globalLockMapSync:
            self.log.info("Acquiring local lock for domain %s (id: %s)",
                          self._sdUUID, hostId)

            hostId, lockFile = self._getLease()

            if lockFile:
                try:
                    utils.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 = utils.NoIntrCall(os.open, self._idsPath, os.O_RDONLY)

            try:
                utils.NoIntrCall(fcntl.flock, lockFile,
                                 fcntl.LOCK_EX | fcntl.LOCK_NB)
            except IOError as e:
                utils.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] = (hostId, lockFile)

        self.log.debug(
            "Local lock for domain %s successfully acquired "
            "(id: %s)", self._sdUUID, hostId)
Beispiel #3
0
    def release(self):
        with self._globalLockMapSync:
            self.log.info("Releasing local lock for domain %s", self._sdUUID)

            hostId, lockFile = self._getLease()

            if not lockFile:
                self.log.debug("Local lock already released for domain %s",
                               self._sdUUID)
                return

            utils.NoIntrCall(os.close, lockFile)
            self._globalLockMap[self._sdUUID] = (hostId, None)

            self.log.debug("Local lock for domain %s successfully released",
                           self._sdUUID)
Beispiel #4
0
 def handle_read(self):
     utils.NoIntrCall(self.socket.read, 1024)