def hasHostId(self, hostId): with self._lock: try: has_host_id = sanlock.inq_lockspace(self._lockspace_name, hostId, self._idsPath) except sanlock.SanlockException: self.log.debug( "Unable to inquire sanlock lockspace " "status, returning False", exc_info=True) return False if has_host_id: # Host id was acquired. Wake up threads waiting in acquire(). self._ready.set() self._end_add_lockspace(hostId) else: if self._ready.valid and self._ready.is_set(): # Host id was released by sanlock. This happens after # renewal failure when storage is inaccessible. self.log.warning("Host id %s for domain %s was released", hostId, self._sdUUID) self._ready.clear() return has_host_id
def hasHostId(self, hostId): with self._lock: try: return sanlock.inq_lockspace(self._sdUUID, hostId, self._idsPath) except sanlock.SanlockException: self.log.debug("Unable to inquire sanlock lockspace " "status, returning False", exc_info=True) return False
def hasHostId(self, hostId): with self._lock: try: return sanlock.inq_lockspace(self._sdUUID, hostId, self._idsPath) except sanlock.SanlockException: self.log.debug( "Unable to inquire sanlock lockspace " "status, returning False", exc_info=True) return False
def acquireHostId(self, hostId, wait): self.log.info("Acquiring host id for domain %s (id=%s, wait=%s)", self._sdUUID, hostId, wait) # Ensure that future calls to acquire() will wait until host id is # acquired. self._ready.valid = True with self._lock: try: with utils.stopwatch("sanlock.add_lockspace"): sanlock.add_lockspace(self._lockspace_name, hostId, self._idsPath, wait=wait) except sanlock.SanlockException as e: if e.errno == errno.EINPROGRESS: # if the request is not asynchronous wait for the ongoing # lockspace operation to complete else silently continue, # the host id has been acquired or it's in the process of # being acquired (async). if wait: if not sanlock.inq_lockspace(self._lockspace_name, hostId, self._idsPath, wait=True): raise se.AcquireHostIdFailure(self._sdUUID, e) self.log.info( "Host id for domain %s successfully " "acquired (id=%s, wait=%s)", self._sdUUID, hostId, wait) self._ready.set() elif e.errno == errno.EEXIST: self.log.info( "Host id for domain %s already acquired " "(id=%s, wait=%s)", self._sdUUID, hostId, wait) self._ready.set() else: raise se.AcquireHostIdFailure(self._sdUUID, e) else: if wait: self.log.info( "Host id for domain %s successfully " "acquired (id=%s, wait=%s)", self._sdUUID, hostId, wait) self._ready.set()
def acquireHostId(self, hostId, async): with self._lock: self.log.info("Acquiring host id for domain %s (id: %s)", self._sdUUID, hostId) try: sanlock.add_lockspace(self._sdUUID, hostId, self._idsPath, async=async) except sanlock.SanlockException as e: if e.errno == errno.EINPROGRESS: # if the request is not asynchronous wait for the ongoing # lockspace operation to complete if not async and not sanlock.inq_lockspace( self._sdUUID, hostId, self._idsPath, wait=True): raise se.AcquireHostIdFailure(self._sdUUID, e) # else silently continue, the host id has been acquired # or it's in the process of being acquired (async) elif e.errno != errno.EEXIST: raise se.AcquireHostIdFailure(self._sdUUID, e)
def hasHostId(self, hostId): with self._lock: try: has_host_id = sanlock.inq_lockspace(self._sdUUID, hostId, self._idsPath) except sanlock.SanlockException: self.log.debug("Unable to inquire sanlock lockspace " "status, returning False", exc_info=True) return False if has_host_id: # Host id was acquired. Wake up threads waiting in acquire(). self._ready.set() else: # Host id was not acquired yet, or was lost, and will be # acquired again by the domain monitor. Future threads calling # acquire() will wait until host id is acquired again. self._ready.clear() return has_host_id
def acquireHostId(self, hostId, wait): self.log.info("Acquiring host id for domain %s (id=%s, wait=%s)", self._sdUUID, hostId, wait) # Ensure that future calls to acquire() will wait until host id is # acquired. self._ready.valid = True with self._lock: try: with utils.stopwatch("sanlock.add_lockspace"): sanlock.add_lockspace(self._sdUUID, hostId, self._idsPath, **{'async': not wait}) except sanlock.SanlockException as e: if e.errno == errno.EINPROGRESS: # if the request is not asynchronous wait for the ongoing # lockspace operation to complete else silently continue, # the host id has been acquired or it's in the process of # being acquired (async). if wait: if not sanlock.inq_lockspace(self._sdUUID, hostId, self._idsPath, wait=True): raise se.AcquireHostIdFailure(self._sdUUID, e) self.log.info("Host id for domain %s successfully " "acquired (id=%s, wait=%s)", self._sdUUID, hostId, wait) self._ready.set() elif e.errno == errno.EEXIST: self.log.info("Host id for domain %s already acquired " "(id=%s, wait=%s)", self._sdUUID, hostId, wait) self._ready.set() else: raise se.AcquireHostIdFailure(self._sdUUID, e) else: if wait: self.log.info("Host id for domain %s successfully " "acquired (id=%s, wait=%s)", self._sdUUID, hostId, wait) self._ready.set()