Change in vdsm[master]: iscsi: Fix minimal timeout when performing scsi scan

nsoffer at redhat.com nsoffer at redhat.com
Thu Mar 26 23:38:28 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: iscsi: Fix minimal timeout when performing scsi scan
......................................................................

iscsi: Fix minimal timeout when performing scsi scan

When performing iscsi rescan, we start an iscsiadm process, and wait at
least 2 seconds before checking if the process terminated. However,
since we use zombiereaper, when iscsiadm terminates, time.sleep() is
interrupted silently, eliminating the minimum timeout. In Vdsm logs we
can see that we wait for about 12 milliseconds instead of 2 seconds.

Without the minimal wait, creating a storage domain may fail after
disconnecting and reconnecting from the storage server, and trying to
access the vg before the multiapth device was created.

The root cause is commit 66c24c1996 (iscsi: Iscsi rescan cleanup), which
replaced blocking scsi scan and interrupt-safe wait loop with
non-blocking scsi scan and single unsafe time.sleep().

The correct solution is performing blocking iscsi scan instead of
sleeping, but it will take time to get right, and we need a minimal fix
now. In this patch, we fix the interruptible sleep with new
utils.uninterruptible_sleep() helper.

Change-Id: Ia4c62ed29c67698d689f8a345e6a740363c77c0d
Bug-Url: https://bugzilla.redhat.com/1205877
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/utils.py
M tests/utilsTests.py
2 files changed, 37 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/56/39256/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 8c1a33c..671be7a 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -1235,6 +1235,21 @@
     return os.times()[4]
 
 
+def uninterruptible_sleep(timeout):
+    """
+    Sleep at least timeout seconds ignoring interrupts.
+
+    time.sleep() may be interrupted silently by signals, returning before the
+    requested timeout has passed.
+    See https://docs.python.org/2/library/time.html#time.sleep
+    """
+    now = monotonic_time()
+    deadline = now + timeout
+    while now < deadline:
+        time.sleep(deadline - now)
+        now = monotonic_time()
+
+
 def random_iface_name(prefix='', max_length=15):
     """
     Create a network device name with the supplied prefix and a pseudo-random
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
index 4914707..e9f3d11 100644
--- a/tests/utilsTests.py
+++ b/tests/utilsTests.py
@@ -731,3 +731,25 @@
 @utils.memoized
 def memoized_function(test, *args):
     return test.get(args)
+
+
+class UniterruptibleSleepTests(TestCaseBase):
+
+    MONOTIME_TICK = 0.01
+
+    def test_sleep(self):
+        self.check(0.2)
+
+    def test_sigchld(self):
+        # When using zombiereaper, we will get SIGCHLD signal when the child
+        # process exit, interrupting time.sleep().
+        utils.execCmd(["sleep", "0.2"], sync=False)
+        self.check(0.4)
+
+    def check(self, timeout):
+        start = utils.monotonic_time()
+        utils.uninterruptible_sleep(timeout)
+        elapsed = utils.monotonic_time() - start
+        self.assertTrue(elapsed > timeout - self.MONOTIME_TICK,
+                        msg="Expected sleep %.2f, slept %.2f" %
+                        (timeout, elapsed))


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

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