Change in vdsm[master]: fencing: Introduce getHostStatus internal API

nsoffer at redhat.com nsoffer at redhat.com
Tue Jun 17 23:55:39 UTC 2014


Nir Soffer has uploaded a new change for review.

Change subject: fencing: Introduce getHostStatus internal API
......................................................................

fencing: Introduce getHostStatus internal API

When fencing another host, we like to check if the other host has access
to storage, to prevent unwanted fencing of a lively host. This patch
adds an internal API for getting another host status on monitored
domains.

The new getHostStatus API returns a dictionary of monitored domains
UUIDs and host status code on each domain. The caller will apply a
fencing policy using this data to decide if host is lively enough to
prevent fencing.

Change-Id: Iccd62e58a194aa0ceb0f5e2503b8ec7e4349971b
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/storage/clusterlock.py
M vdsm/storage/domainMonitor.py
M vdsm/storage/hsm.py
M vdsm/storage/sd.py
4 files changed, 43 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/28873/1

diff --git a/vdsm/storage/clusterlock.py b/vdsm/storage/clusterlock.py
index 6ca3e03..a23919e 100644
--- a/vdsm/storage/clusterlock.py
+++ b/vdsm/storage/clusterlock.py
@@ -91,6 +91,9 @@
     def hasHostId(self, hostId):
         return True
 
+    def getHostStatus(self, hostId):
+        return sanlock.HOST_UNKNOWN
+
     def acquire(self, hostID):
         leaseTimeMs = self._leaseTimeSec * 1000
         ioOpTimeoutMs = self._ioOpTimeoutSec * 1000
@@ -225,6 +228,19 @@
                                "status, returning False", exc_info=True)
                 return False
 
+    def getHostStatus(self, hostId):
+        try:
+            # Note: get_hosts has of-by-one bug when asking for particular host
+            # id, so get all and filter.
+            hosts = sanlock.get_hosts(self._sdUUID)
+        except sanlock.SanlockException as e:
+            self.log.debug("Error getting host status: %s", e)
+        else:
+            for info in hosts:
+                if info['host_id'] == hostId:
+                    return info['flags']
+        return sanlock.HOST_UNKNOWN
+
     # The hostId parameter is maintained here only for compatibility with
     # ClusterLock. We could consider to remove it in the future but keeping it
     # for logging purpose is desirable.
@@ -358,6 +374,9 @@
             currentHostId, lockFile = self._getLease()
             return currentHostId == hostId
 
+    def getHostStatus(self, hostId):
+        return sanlock.HOST_UNKNOWN
+
     def acquire(self, hostId):
         with self._globalLockMapSync:
             self.log.info("Acquiring local lock for domain %s (id: %s)",
diff --git a/vdsm/storage/domainMonitor.py b/vdsm/storage/domainMonitor.py
index 8a50b4f..5f4a086 100644
--- a/vdsm/storage/domainMonitor.py
+++ b/vdsm/storage/domainMonitor.py
@@ -21,6 +21,7 @@
 from threading import Thread, Event
 from time import time
 import weakref
+import sanlock
 
 import logging
 import misc
@@ -121,6 +122,12 @@
     def getStatus(self, sdUUID):
         return self._domains[sdUUID].getStatus()
 
+    def getHostStatus(self, hostId):
+        status = {}
+        for sdUUID, monitor in self._domains.items():
+            status[sdUUID] = monitor.getHostStatus(hostId)
+        return status
+
     def close(self):
         self.log.info("Stopping domain monitors")
         for sdUUID in self._domains.keys():
@@ -160,6 +167,11 @@
     def getStatus(self):
         return self.status.copy()
 
+    def getHostStatus(self, hostId):
+        if self.domain:
+            return self.domain.getHostStatus(hostId)
+        return sanlock.HOST_UNKNOWN
+
     @utils.traceback(on=log.name)
     def _monitorLoop(self):
         self.log.debug("Starting domain monitor for %s", self.sdUUID)
diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index 36076c2..647a277 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -3614,3 +3614,12 @@
         with rmanager.acquireResource(STORAGE, HSM_DOM_MON_LOCK,
                                       rm.LockType.exclusive):
             self.domainMonitor.stopMonitoring(sdUUID)
+
+    @public
+    def getHostStatus(self, hostId):
+        """
+        Returns host status on monitored domains.
+
+        Warning: Internal use only.
+        """
+        return {'host_status': self.domainMonitor.getHostStatus(hostId)}
diff --git a/vdsm/storage/sd.py b/vdsm/storage/sd.py
index a868f38..34952d7 100644
--- a/vdsm/storage/sd.py
+++ b/vdsm/storage/sd.py
@@ -481,6 +481,9 @@
     def hasHostId(self, hostId):
         return self._clusterLock.hasHostId(hostId)
 
+    def getHostStatus(self, hostId):
+        return self._clusterLock.getHostStatus(hostId)
+
     def hasVolumeLeases(self):
         domVersion = self.getVersion()
         try:


-- 
To view, visit http://gerrit.ovirt.org/28873
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccd62e58a194aa0ceb0f5e2503b8ec7e4349971b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list