FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 01-31-2012, 01:14 PM
Radek Vykydal
 
Default iscsi: no discovery on each target login (UI) (#752066)

Resolves: rhbz#752066

GUI case.

Don't redo discovery each time when logging to a node.
Skip it if already logged to a node on the same address.
Instead, store the node list on the first discovery. Next discovery
would rewrite information about credentials used for previous login
stored by iscsilib's setAuth() (and accessed later by getAuth()) in
database in /var/lib/iscsi/nodes.
---
partIntfHelpers.py | 4 +--
storage/iscsi.py | 91 +++++++++++++++++++++++++++++++++++++--------------
2 files changed, 67 insertions(+), 28 deletions(-)

diff --git a/partIntfHelpers.py b/partIntfHelpers.py
index 5a54ba6..104ffd1 100644
--- a/partIntfHelpers.py
+++ b/partIntfHelpers.py
@@ -463,14 +463,12 @@ def drive_iscsi_addition(anaconda, wizard):
discovery_dict = wizard.get_discovery_dict()
discovery_dict["intf"] = anaconda.intf
found_nodes = anaconda.id.storage.iscsi.discover(**discovery_dic t)
- map(lambda node: log.debug("discovered iSCSI node: %s" % node.name),
- found_nodes)
step = STEP_NODES
elif step == STEP_NODES:
if len(found_nodes) < 1:
log.debug("iscsi: no new iscsi nodes discovered")
anaconda.intf.messageWindow(_("iSCSI Nodes"),
- _("No new iSCSI nodes discovered"))
+ _("No iSCSI nodes to log in"))
break
(rc, selected_nodes) = wizard.display_nodes_dialog(found_nodes)
if not rc or len(selected_nodes) == 0:
diff --git a/storage/iscsi.py b/storage/iscsi.py
index c75b977..9c149f8 100644
--- a/storage/iscsi.py
+++ b/storage/iscsi.py
@@ -28,6 +28,7 @@ import shutil
import time
import hashlib
import random
+import itertools
log = logging.getLogger("anaconda")

import gettext
@@ -94,8 +95,9 @@ class iscsi(object):
"""

def __init__(self):
- # This list contains all nodes
- self.nodes = []
+ # Dictionary of discovered targets containing list of (node,
+ # logged_in) tuples.
+ self.discovered_targets = {}
# This list contains nodes discovered through iBFT (or other firmware)
self.ibftNodes = []
self._initiator = ""
@@ -129,6 +131,29 @@ class iscsi(object):

initiator = property(_getInitiator, _setInitiator)

+ def active_nodes(self, target=None):
+ """Nodes logged in to"""
+ if target and target in self.discovered_targets:
+ return [node for (node, logged_in) in
+ self.discovered_targets[target]
+ if logged_in]
+ else:
+ return [node for (node, logged_in) in
+ itertools.chain(*self.discovered_targets.values())
+ if logged_in] + self.ibftNodes
+
+ def _mark_node_active(self, node, active=True):
+ """Mark node as one logged in to
+
+ Returns False if not found
+ """
+ for target_nodes in self.discovered_targets.values():
+ for nodeinfo in target_nodes:
+ if nodeinfo[0] is node:
+ nodeinfo[1] = active
+ return True
+ return False
+
def _startIBFT(self, intf = None):
if not flags.ibft:
return
@@ -144,7 +169,6 @@ class iscsi(object):
node.login()
log.info("iscsi IBFT: logged into %s at %s:%s through %s" % (
node.name, node.address, node.port, node.iface))
- self.nodes.append(node)
self.ibftNodes.append(node)
except IOError, e:
log.error("Could not log into ibft iscsi target %s: %s" %
@@ -219,35 +243,51 @@ class iscsi(object):
def discover(self, ipaddr, port="3260", username=None, password=None,
r_username=None, r_password=None, intf=None):
"""
- Discover iSCSI nodes on the target.
+ Discover iSCSI nodes on the target available for login.
+
+ If we are logged in a node discovered for specified target
+ do not do the discovery again as it can corrupt credentials
+ stored for the node (setAuth and getAuth are using database
+ in /var/lib/iscsi/nodes which is filled by discovery). Just
+ return nodes obtained and stored in the first discovery
+ instead.

- Returns list of new found nodes.
+ Returns list of nodes user can log in.
"""
authinfo = None
- found = 0
- logged_in = 0

if not has_iscsi():
raise IOError, _("iSCSI not available")
if self._initiator == "":
raise ValueError, _("No initiator name set")

- if username or password or r_username or r_password:
- # Note may raise a ValueError
- authinfo = libiscsi.chapAuthInfo(username=username,
- password=password,
- reverse_username=r_username,
- reverse_password=r_password)
- self.startup(intf)
+ if self.active_nodes((ipaddr, port)):
+ log.debug("iSCSI: skipping discovery of %s:%s due to active nodes" %
+ (ipaddr, port))
+ else:
+ if username or password or r_username or r_password:
+ # Note may raise a ValueError
+ authinfo = libiscsi.chapAuthInfo(username=username,
+ password=password,
+ reverse_username=r_username,
+ reverse_password=r_password)
+ self.startup(intf)
+
+ # Note may raise an IOError
+ found_nodes = libiscsi.discover_sendtargets(address=ipaddr,
+ port=int(port),
+ authinfo=authinfo)
+ if found_nodes is None:
+ found_nodes = []
+ self.discovered_targets[(ipaddr, port)] = []
+ for node in found_nodes:
+ self.discovered_targets[(ipaddr, port)].append([node, False])
+ log.debug("discovered iSCSI node: %s" % node.name)

- # Note may raise an IOError
- found_nodes = libiscsi.discover_sendtargets(address=ipaddr,
- port=int(port),
- authinfo=authinfo)
- if found_nodes is None:
- return []
# only return the nodes we are not logged into yet
- return [n for n in found_nodes if n not in self.nodes]
+ return [node for (node, logged_in) in
+ self.discovered_targets[(ipaddr, port)]
+ if not logged_in]

def log_into_node(self, node, username=None, password=None,
r_username=None, r_password=None, intf=None):
@@ -273,7 +313,8 @@ class iscsi(object):
rc = True
log.info("iSCSI: logged into %s at %s:%s through %s" % (
node.name, node.address, node.port, node.iface))
- self.nodes.append(node)
+ if not self._mark_node_active(node):
+ log.error("iSCSI: node not found among discovered")
except (IOError, ValueError) as e:
msg = str(e)
log.warning("iSCSI: could not log into %s: %s" % (node.name, msg))
@@ -349,7 +390,7 @@ class iscsi(object):
if not self.initiatorSet:
return
f.write("iscsiname %s
" %(self.initiator,))
- for n in self.nodes:
+ for n in self.active_nodes():
f.write("iscsi --ipaddr %s --port %s --target %s" %
(n.address, n.port, n.name))
auth = n.getAuth()
@@ -368,7 +409,7 @@ class iscsi(object):

# set iscsi nodes to autostart
root = anaconda.id.storage.rootDevice
- for node in self.nodes:
+ for node in self.active_nodes():
autostart = True
disks = self.getNodeDisks(node, anaconda.id.storage)
for disk in disks:
@@ -393,7 +434,7 @@ class iscsi(object):
symlinks=True)

def getNode(self, name, address, port):
- for node in self.nodes:
+ for node in self.active_nodes():
if node.name == name and node.address == address and
node.port == int(port):
return node
--
1.7.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 07:48 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org