[NEW PATCH] BZ#717868: Use iscsiadm return code to indicate existing session (via gerrit-bot)
David Naori
dnaori at redhat.com
Mon Aug 1 08:40:12 UTC 2011
New patch submitted by David Naori (dnaori at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/770
commit 6927d2020040f9549263cd30795eaaa3a0cdae38
Author: David Naori <dnaori at redhat.com>
Date: Mon Aug 1 09:07:37 2011 +0300
BZ#717868: Use iscsiadm return code to indicate existing session
Now that iscsiadm return ISCSI_ERR_SESS_EXISTS in case session
is already logged in, we can use that and remove checkSession().
Change-Id: I67c8fc5430dd548877b26c802bcd3b3e775a20fe
diff --git a/vdsm/storage/iscsi.py b/vdsm/storage/iscsi.py
index 75f1542..1d5bf90 100644
--- a/vdsm/storage/iscsi.py
+++ b/vdsm/storage/iscsi.py
@@ -244,6 +244,9 @@ discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
# a preference of disabling the checking.
"""
+# iscsiadm exit statuses
+ISCSI_ERR_SESS_EXISTS = 15
+
log = logging.getLogger('Storage.iScsi')
def isConfigured():
@@ -469,15 +472,11 @@ def addiSCSINode(ip, port, iqn, tpgt, initiator, username=None, password=None):
# Finally instruct the iscsi initiator to login to the target
cmd = cmdt + ["-l", "-p", portal]
rc = misc.execCmd(cmd)[0]
- if rc != 0:
+ if rc not in (0, ISCSI_ERR_SESS_EXISTS):
raise se.iSCSILoginError(portal)
+
except se.StorageException:
exc_class, exc, tb = sys.exc_info()
- try:
- if checkSession(ip, port, iqn, tpgt, username, password):
- return 0
- except Exception:
- log.error("Could not get iscsi session list", exc_info=True)
# Do not try to disconnect - we may remove live node!
try:
remiSCSINode(ip, port, iqn, tpgt, username, password, logout=False)
@@ -528,95 +527,6 @@ def forceIScsiScan():
# Ignore exception, there is nothing intelligent we can do about it
log.warning("Failed to rescan host %s", host, exc_info=True)
- at misc.samplingmethod
-def _getiSCSISessionList():
- """
- Collect the list of active iSCSI sessions
- """
- cmd = [constants.EXT_ISCSIADM, "-m", "session"]
- (rc, out, err) = misc.execCmd(cmd)
- if rc != 0:
- raise se.GetiSCSISessionListError
-
- # Parse the strings in form
- # tcp: [23] [multipass]:3260,1 iqn.1986-03.com.sun:02:9c576850-ea49-ebdc-d0af-c4db33981227
- # tcp: [24] 10.35.1.99:3260,1 iqn.2006-01.com.openfiler:clear
- # tcp: [26] 10.35.1.99:3260,1 iqn.2006-01.com.openfiler:cheesy
-
- sessions = []
- keys = ['connection', 'port', 'iqn', 'portal', 'user', 'password']
- user = password = ""
- for i in out:
- p, iqn = i.split()[2:]
- host, p2 = p.split(":")
- host = host.strip("[]")
- port, tpgt = p2.split(",")
- v = [host, port, iqn, tpgt, user, password]
- sessions.append(dict(zip(keys, v)))
- return sessions
-
-def _safeGethostbyname(host):
- try:
- return socket.gethostbyname(host)
- except socket.gaierror:
- return host
-
-def sameSession(enta, entb):
- for k, va in enta.iteritems():
- if k in ['portal', 'user', 'password']:
- continue
-
- if not va:
- continue
-
- try:
- vb = entb[k]
- except KeyError:
- return False
-
- # Portal is not used, user/password not relevant to existing session
- if k == "connection":
- va = _safeGethostbyname(va)
- vb = _safeGethostbyname(vb)
-
- elif k == 'port':
- va = int(va)
- vb = int(vb)
-
- if va != vb:
- log.debug("enta key %s v %s != entb v %s" % (k, va, vb))
- return False
- return True
-
-def checkSessionList(sessionList):
- l = _getiSCSISessionList()
- result = []
- keys = ['connection', 'port', 'iqn', 'portal', 'user', 'password']
- for sessionArgs in sessionList:
- # this might contain the cid at the start. Handle bothe cases
- try:
- host, port, iqn, tpgt, user, password = sessionArgs[-6:]
- except ValueError:
- result.append(False)
- continue
- found = False
- dest = dict(zip(keys, [host, port, iqn, tpgt, user, password]))
- log.debug("checkSession: dest %s" % ([e + ": " + str(dest[e]) for e in dest if e != 'password']))
- for ent in l:
- if sameSession(ent, dest):
- result.append(True)
- found = True
- break
- if not found:
- result.append(False)
- return result
-
-def checkSession(host, port, iqn, tpgt, user=None, password=None):
- """
- Check if a session is active
- """
- return checkSessionList([[host, port, iqn, tpgt, user, password]])[0]
-
def devIsiSCSI(dev):
hostdir = os.path.realpath(os.path.join("/sys/block", dev, "device/../../.."))
host = os.path.basename(hostdir)
More information about the vdsm-patches
mailing list