File lio-utils-retry-enabling-fileio-target.patch of Package lio-utils.1565
From: Lee Duncan
Date: Thu Nov 19 14:15:22 PST 2015
Subject: retrying enabling FILEIO target
Reference: bsc#940636
When trying to enable a newly create target in
sysfs, if we are too fast, the target might not
yet be fully set, since the time between creating
the target (with a mkdir in sysfs) and the time
when the target is fully set up is indetermanent.
This patch enables 3 retries, at one second each,
when trying to enable a target.
---
tcm-py/tcm_fileio.py | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
--- a/tcm-py/tcm_fileio.py
+++ b/tcm-py/tcm_fileio.py
@@ -3,10 +3,37 @@
import os
import subprocess as sub
import string, re
+import time
from optparse import OptionParser
tcm_root = "/sys/kernel/config/target/core"
+def write_with_retries(attr_value, attr_path, newline=True, retries=5):
+ """
+ Write an attribute value to an attribute path, followed by an
+ optional newline, with retries if needed. Return boolean
+ success or failure.
+ """
+ success = False
+ while 1:
+ try:
+ with open(attr_path, 'w') as attr_file:
+ if newline:
+ print >>attr_file, attr_value
+ else:
+ print >>attr_file, attr_value,
+ success=True
+ break
+ except Exception, e:
+# print "DEBUG: write failed", e
+ retries = retries - 1
+ if not retries:
+ break
+ time.sleep(1)
+# print "DEBUG: write '%s' to '%s': success=%s, retries left=%d" % \
+# (attr_value, attr_path, success, retries)
+ return success
+
def createvirtdev(path, params):
# print "Calling fileio createvirtdev: path " + path
@@ -40,13 +67,12 @@ def createvirtdev(path, params):
print "FILEIO: createvirtdev failed for control_opt with " + params[0]
return -1
- enable_opt = "echo 1 > " + cfs_path + "enable"
-# print "Calling enable_opt " + enable_opt
- ret = os.system(enable_opt)
- if ret:
+ if not write_with_retries("1", cfs_path + "enable"):
print "FILEIO: createvirtdev failed for enable_opt with " + params[0]
return -1
+ return 0
+
def fd_freevirtdev():
pass