Change in vdsm[master]: fc-scan: Use utilities from vdsm library.

nsoffer at redhat.com nsoffer at redhat.com
Mon Mar 9 00:08:39 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: fc-scan: Use utilities from vdsm library.
......................................................................

fc-scan: Use utilities from vdsm library.

Replace low level threading code with simpler concurrent.tmap() call and
duplicate monotonic_time() with utils.monotonic_time().

Change-Id: Ic48748d6a43d41e034e16cb4f636ebe627881590
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/storage/fc-scan
1 file changed, 24 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/38466/1

diff --git a/vdsm/storage/fc-scan b/vdsm/storage/fc-scan
index 344345d..c746ea4 100755
--- a/vdsm/storage/fc-scan
+++ b/vdsm/storage/fc-scan
@@ -38,43 +38,11 @@
 import logging
 import os
 import sys
-import threading
+
+from vdsm import concurrent
+from vdsm import utils
 
 log = logging.getLogger("fc-scan")
-
-
-class Scan(object):
-
-    def __init__(self, host):
-        self.host = host
-        self.succeeded = False
-        self.thread = None
-
-    def start(self):
-        self.thread = threading.Thread(target=self.run)
-        self.thread.daemon = True
-        self.thread.start()
-
-    def wait(self):
-        self.thread.join()
-
-    def run(self):
-        try:
-            path = "/sys/class/scsi_host/%s/scan" % self.host
-            log.debug("Scanning %s", path)
-            start = monotonic_time()
-            fd = os.open(path, os.O_WRONLY)
-            try:
-                os.write(fd, "- - -")
-            finally:
-                os.close(fd)
-            self.succeeded = True
-            elapsed = monotonic_time() - start
-            log.debug("Scanned %s in %.2f seconds", path, elapsed)
-        except OSError as e:
-            log.error("Scanning %s failed: %s", path, e)
-        except Exception:
-            log.exception("Scanning %s failed", path)
 
 
 def main(args):
@@ -93,22 +61,32 @@
         log.debug("No fc_host found")
         return 0
 
-    scans = []
-
-    for host in hosts:
-        s = Scan(host)
-        s.start()
-        scans.append(s)
-
-    for s in scans:
-        s.wait()
+    scans = concurrent.tmap(scan_host, hosts)
 
     if not all(s.succeeded for s in scans):
         return 1
 
+    return 0
 
-def monotonic_time():
-    return os.times()[4]
+
+def scan_host(name):
+    try:
+        path = "/sys/class/scsi_host/%s/scan" % name
+        log.debug("Scanning %s", path)
+        start = utils.monotonic_time()
+        fd = os.open(path, os.O_WRONLY)
+        try:
+            os.write(fd, "- - -")
+        finally:
+            os.close(fd)
+        elapsed = utils.monotonic_time() - start
+        log.debug("Scanned %s in %.2f seconds", path, elapsed)
+    except OSError as e:
+        log.error("Scanning %s failed: %s", path, e)
+        raise
+    except Exception:
+        log.exception("Scanning %s failed", path)
+        raise
 
 
 if __name__ == '__main__':


-- 
To view, visit https://gerrit.ovirt.org/38466
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic48748d6a43d41e034e16cb4f636ebe627881590
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