Blob Blame History Raw
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/Changelog open-iscsi-2.0-872-rc4-bnx2i.sync/Changelog
--- open-iscsi-2.0-872-rc4-bnx2i/Changelog	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/Changelog	2011-08-14 16:48:25.000000000 -0500
@@ -1,132 +1,114 @@
-open-iscsi-2.0-871 - open-iscsi-2.0.870
+open-iscsi-2.0-872 - open-iscsi-2.0.871
 
-Boaz Harrosh (1):
-      open-iscsi: Makefile: separate out user: and kernel: make targets
+Avi Kaplan (2):
+      Remove unused field iscsi_conn from struct iscsi_sw_tcp_conn
+      Change restore_callbacks argument iscsi_sw_tcp_conn to iscsi_conn
 
 Erez Zilber (1):
-      Add Module.markers to .gitignore
+      Fix 2.6.14-23_compat.patch to support all RHEL 5.X versions
 
-Karen Xie (2):
-      userspace - add new transport cxgb3i
-      userspace - setting interface ip address
-
-Mike Christie (84):
-      iscsid: fix relogin retry handling
-      iscsid idbm: print out header and tail to seperate records
-      ibft: add support to use iscsi_ibft module and log into all portals found in firmware
-      fwparam: rm unused filepath argument
-      iscsid idbm: move record strings to header
-      iscsiadm: discovery mode supports the --show
-      iscsiadm: have fw discovery handle --op arguments
-      iscsiadm: fix output ordering
-      iscsi modules: fix compilation
-      iscsid/iscsiadm: fix strto* usage
-      iscsid: fix logout response and time2wait handling
-      iscsiadm: remove default bnx2i iface
-      iscsid/iscsiadm: support multiple inititor names per host.
-      iscsiadm: print session and session info running through ifaces in iface mode
-      iscsid: update transport handle
-      idbm: have idbm_rec_update_param update the value string of the matching rec_info
-      iscsi mod: sync up kernel modules with 2.6.29
-      iscsi mod: 2.6.27 compat
-      iscsi mod: 2.6.26 compat
-      iscsi mod: 2.6.24-25 compat
-      iscsi mod: 2.6.20-23 compat
-      iscsi mod: 2.6.14-19 compat
-      iscsi mod: fix up 2.6.14-19 compat patch
-      iscsi mod iscsi_tcp: compat fix for pI4/pI6
-      build: add a make user
-      iscsi tools: fix chap
-      PATCH: iscsi tools: do not use exit()
-      PATCH: fix iBFT firmware reading with newer kernels
-      2.6.29-rc libiscsi: Fix scsi command timeout oops in iscsi_eh_timed_out
-      iscsi mod: 2.6.14-19 compat
-      iscsi tools: convert from strncat to strlcat
-      iscsi tools: convert from strncpy to strlcpy
-      iscsi tool make: add notification that iscsi start was made
-      iscsid: Fix up connection failed messages
-      docs: fix up iscsiadm man page iface info
-      iscsi tools: update version in preparation for new release
-      iscsid: flush sysfs cache.
-      iscsid: mv event loop code to new file
-      docs: update readme with libiscsi_tcp info
-
-
-
-
--------------------------------------------------------------------
-open-iscsi-2.0-870 - open-iscsi-2.0.869
-
-Doron Shoham (1):
-      log.c: add error messages when allocation shared memory
-
-Erez Zilber (2):
-      Minor fixes in iscsi_discovery documentation
-      rm unused variable in fw_entry.c
-
-Hannes Reinecke (1):
-      Add SLES10 SP2 compat
-
-Hans de Goede (1):
-      PATCH: add error checking to iscsi discovery db lock creation
-
-Mike Christie (58):
-      change mgmt_ipc to logout by sid
-      iscsi class/if kernel: add ifacename attr
-      add ifacename support tools
-      rm db param
-      rm num_transports from sysfs header.
-      Add bind by initiatorname
-      break up iface code and add default iser, tcp/default and bnx2i ifaces
-      Use startup definition in util.c.
-      set header digests to off by default
-      fix compile warning for missing iface.h
-      User 64 bit params mask.
-      Do not allow iface setting to be changed in node mode.
-      Fix bad merge. User iscsi param masks instead of params.
-      Support mutlple ifaces with the same binding (lack of binding).
-      Release transport entry when the transport is unloaded
-      Fix ep_disconnect handling of invalid ep
-      libiscsi: Fix nop timeout handling
-      libiscsi: fix recv tmo
-      Revert Release-transport-entry-when-the-transport-is-unload.patch
-      pass ep to session creation
-      Fix iser create bound session compat
-      fix compilation on Fedora 9
-      Fix sysfs handling of block:sdX and scsi bus changes
-      Only autobind to ifaces with transport = tcp
-      Increase login retry for iscsistart.
-      Sync kernel modules to scsi-misc for 2.6.27.
-      Update 2.6.14 - 2.6.19 compat patch
-      Update 2.6.20 - 2.6.24 patch
-      Update 2.6.24 - 2.6.25 patch
-      iscsid: don't print enosys errors.
-      libiscsi: support older tools that did not set can_queue/cmds_max
-      Fix transport_name compat support.
-      Fix idbm iscsid segfault when accsing ifaces
-      Fix discovery and autobinding
-      fix ipv6 login redirect support.
-      Fix login redirect failure handling.
-      remove sysfs_file
-      fix dynamic tpgt support.
-      Bump version for new release.
-      Add compat patch for RHEL 5.2
-      iscsid: adjust requested settings for user
-      Sync kernel modules with 2.6.27
-      Add 2.6.26 compat support
-      Add Makefile support for 2.6.26 compat patch
-      Add .gitignore files
-      Revert broken SLES 10 compat patch.
-      iscsi conf: increase default login max
-      iscsi conf: partially revert increase default login max change
-      modify initial login retry max
-      libiscsi: fix data corruption when target has to resend data-in packets
-      iscsi class: fix endpoint id handling
-      handle ISCSI_ERR_INVALID_HOST
-      iscsi_tcp: return a descriptive error value during connection errors
-      libiscsi: fix locking in iscsi_eh_device_reset
-      update 2.6.14-19_compat.patch
-      update 2.6.20-21_compat.patch
-      update 2.6.24_compat.patch
-      Fix initiator.c compile warning
+Hannes Reinecke (2):
+      Allow update of discovery records.
+      Update 2.6.27_compat.patch for SLES 11
+
+Mike Christie (91):
+      Don't kill iscsid if logout from all nodes fail
+      iscsid: fix ISCSI_ERR_INVALID_HOST err handling
+      iscsid: add flag to indicate if driver needs iscsid to set ip
+      iscsid: add be2iscsi template
+      iscsid be2iscsi: add more driver limits
+      iscsid: start iscsid automatically when needed
+      iscsid: fix segfault during session sync up
+      iscsiadm: fix discovery record use
+      iscsi mod: sync to linux-2.6-iscsi tree's 2.6.33 feature window patches
+      iscsid: handle new replacement_timeout values
+      iscsi tools: support tgt reset timeout
+      iscsi-iname: fix misleading help description
+      iscsid: fix iferror log message
+      iscsi mod: Update 2.6.14-23_compat.patch patch
+      iscsiadm: fix login/logout message
+      do not use a semarg in shared-mem for semop calls
+      Fix wrong logs in log.c
+      update 2.6.26 compat patch
+      iscsi tools: Allow empty username for CHAP
+      iscsi ibft/boot: fix net dev loopup
+      iscsistart option to bring up NICs using configuration in iBFT.
+      ibft boot: mv setup nics to fw_entry.c so iscsiadm can use it
+      iscsistart ibft: fix fwparam network cmd
+      iscsid be2iscsi: don't set set_host_ip
+      iscsi tools: merge functions to get net iface name from mac address
+      ibft boot: do not setup nic if offload can be used
+      iscsistart ibft boot: setup iscsi offload during boot
+      ibft boot: remove be2iscsi
+      iscsi tools: idbm/fw function cleanup
+      iscsi tool: trivial fixes
+      ibft boot: add offload ibft support to iscsiadm
+      iscsiadm: only do auto iface setup when iface mode is run
+      ibft boot: add iscsiadm offload ibft rec support
+      doc: add iscsistart man page
+      doc: add iscsi-iname man page
+      ibft boot: fix dev to iface matching
+      offload boot: turn off
+      iscsi tools: nic setup cleanup
+      iscsi tools: fix compile errors
+      iscsi kern: fix 2.6.27 compat patch
+      iscsiadm: add nonpersistent mode to discovery mode
+      iscsi tool: mv idbm_node_setup_defaults to idbm.c
+      iscsi tools: cleanup get_global_string_param use
+      iscsi tools: make config file parser a little smarter.
+      iscsiadm: mv session management functions to new file
+      st discovery: fix reopen max handling
+      iscsid: have iscsid watch for new portals using sendtargets
+      iscsi tools: mv iscsid request helpers to its own file
+      iscsi tools: add str prefix to strings.c functions
+      iscsi tools: use open-isns services
+      iscsi tools: add MaxXmitDataSegmentLength param
+      iscsi tools: do not exit on mem alloc failures during discovery
+      Fix makefile cleanup
+      iscsid: add isns discovery daemon and SCN support
+      iscsid: support discovery daemon auto logout
+      isns: fix compilation
+      iscsi tools: fix null sysfs string handling
+      iscsi tools: fix compilation on s390
+      Update version number to 872
+      iscsi tools: fix MaxXmitDataSegmentLength=0 handling
+      be2iscsi iscsi tool: fix MaxXmitDataSegmentLength handling
+      iscsi tools: be2iscsi: fix initial_r2t_en handling
+      iscsi tools: prep for userspace libiscsi
+      iscsi tools: add log_info helper
+      iscsi tools: fix port handling for iscsiadm commands
+      iscsi tools: fix port handling for iscsiadm commands take 2
+      iscsid: fix discoveryd shutdown
+      iscsi scripts: use iscsiadm -k to shutdown daemon
+      iscsiadm: fix discovery record management
+      iscsid: fix sendtargets discovery daemon CHAP handling
+      iscsiadm: mv disc code to new function
+      iscsiadm: fix disc port handling
+      iscsiadm: add new discovery mode
+      iscsiadm: add isns db support
+      iscsiadm: cleanup default port handling
+      iscsid: use isns discovery rec for isns discoveryd setttings
+      iscsiadm: fix iface mode ENODEV handling
+      iscsiadm: mark discovery mode as depreciated
+      sync to upstream
+      2.6.33 - 34 kernel compat patch
+      2.6.28 - 32 kernel compat patch
+      2.6.27 kernel compat patch
+      2.6.26 kernel compat patch
+      2.6.24 - 25 kernel compat patch
+      2.6.14 - 23 kernel compat patch
+      iscsiadm: fix discovery2 db op return value
+      iscsiadm: print isns recs in discovery mode
+      iscsi boot: add support for iscsi boot sysfs module
+      iscsiadm: rename discovery2 mode as discoverydb
+      iscsiadm: fix boot code compile error
+      iscsiadm: fix iface update/delete return value fix
+
+Ritesh Raj Sarraf (3):
+      fix some spelling errors reported by lintian
+      minor manpage updates
+      Fix CVE-2009-1297
+
+Wulf C. Krueger (1):
+      Use DESTDIR when generating an InitiatorName.
 
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/doc/iscsiadm.8 open-iscsi-2.0-872-rc4-bnx2i.sync/doc/iscsiadm.8
--- open-iscsi-2.0-872-rc4-bnx2i/doc/iscsiadm.8	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/doc/iscsiadm.8	2011-08-14 16:48:25.000000000 -0500
@@ -10,13 +10,13 @@ iscsiadm \- open-iscsi administration ut
 \fBiscsiadm\fR \-m node [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-L all,manual,automatic ] [ \-U all,manual,automatic ] [ \-S ] [ [ \-T targetname \-p ip:port \-I iface ] [ \-l | \-u | \-R | \-s] ]
 [ [ \-o operation ]  [ \-n name ] [ \-v value ] [ \-p ip:port ] ]
 
-\fBiscsiadm\fR \-m session [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-r sessionid | sysfsdir [ \-R ] [ \-u | \-s ] ]
+\fBiscsiadm\fR \-m session [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-r sessionid | sysfsdir [ \-R ] [ \-u | \-s | \-o new ] ]
 
-\fBiscsiadm\fR \-m iface [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-I ifacename ] [ [ \-o  operation  ] [ \-n name ] [ \-v value ] ]
+\fBiscsiadm\fR \-m iface [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-I ifacename | \-H hostno|MAC ]   [ [ \-o  operation  ] [ \-n name ] [ \-v value ] ]
 
 \fBiscsiadm\fR \-m fw [\-l]
 
-\fBiscsiadm\fR \-m host [ \-P printlevel ] [ \-H hostno ]
+\fBiscsiadm\fR \-m host [ \-P printlevel ] [ \-H hostno|MAC ]
 
 \fBiscsiadm\fR \-k priority
 
@@ -49,7 +49,13 @@ print debugging information. Valid value
 display help text and exit
 
 .TP
-\fB\-I\fR, \fB\-\-interface\fI[iface]\fR
+\fB\-H\fR, \fB\-\-host=\fI[hostno|MAC]\fR
+The host agrument specifies the SCSI host to use for the operation. It can be
+the scsi host number assigned to the host by the kernel's scsi layer, or the
+MAC address of a scsi host.
+
+.TP
+\fB\-I\fR, \fB\-\-interface=\fI[iface]\fR
 The interface argument specifies the iSCSI interface to use for the operation.
 iSCSI interfaces (iface) are defined in /etc/iscsi/ifaces. For hardware
 iSCSI (qla4xxx) the iface config must have the hardware address
@@ -141,6 +147,8 @@ operator.
 Specifies a database operator \fIop\fR. \fIop\fR must be one of
 \fInew\fR, \fIdelete\fR, \fIupdate\fR, \fIshow\fR or \fInonpersistent\fR.
 .IP
+For iface mode, \fIapply\fR and \fIapplyall\fR  are also applicable.
+.IP
 This option is valid for all modes except fw. Delete should not be used on a running session. If it is iscsiadm will stop the session and then delete the
 record.
 .IP
@@ -148,7 +156,8 @@ record.
 \fIrecid\fR is the target name and portal (IP:port). In iface mode, the \fIrecid\fR
 is the iface name. In discovery mode, the \fIrecid\fR is the portal and
 discovery type.
-
+.IP
+In session mode, the \fInew\fR operation logs in a new session using the same node database and iface information as the specified session.
 .IP
 In discovery mode, if the \fIrecid\fR and new operation is passed in, but the \fI--discover\fR argument is not, then iscsiadm will only create a discovery record (it will not perform discovery). If the \fI--discover\fR argument is passed in with the portal and discovery type, then iscsiadm will create the discovery record if needed, and it will create records for portals returned by the target that do not yet have a node DB record.
 .IP
@@ -163,10 +172,22 @@ sid is passed in.
 .IP
 \fInonpersistent\fR instructs iscsiadm to not manipulate the node DB.
 
+.IP
+\fIapply\fR will cause the network settings to take effect on the specified iface.
+
+.IP
+\fIapplyall\fR will cause the network settings to take effect on all the ifaces whose MAC address or host number matches that of the specific host.
+
 .TP
 \fB\-p\fR, \fB\-\-portal=\fIip[:port]\fR
-Use target portal with ip-address \fIip\fR and \fIport\fR, the default
-\fIport\fR value is 3260.
+Use target portal with ip-address \fIip\fR and \fIport\fR. If port is not passed
+in the default \fIport\fR value is 3260.
+.IP
+IPv6 addresses can bs specified as [ddd.ddd.ddd.ddd]:port or
+ddd.ddd.ddd.ddd.
+.IP
+Hostnames can also be used for the ip argument.
+
 .IP
 This option is only valid for discovery, or for node operations with
 the \fInew\fR operator.
@@ -294,6 +315,152 @@ or
 SendTargets (st)
 discovery type. An SLP implementation is under development.
 
+.SH EXIT STATUS
+ 
+On success 0 is returned. On error one of the return codes below will
+be returned.
+
+Commands that operation on multiple objects (sessions, records, etc),
+iscsiadm/iscsistart will return the first error that is encountered.
+iscsiadm/iscsistart will attempt to execute the operation on the objects it
+can. If no objects are found ISCSI_ERR_NO_OBJS_FOUND is returned.
+
+
+.TP
+.B
+0
+ISCSI_SUCCESS - command executed successfully.
+
+.TP
+.B
+1
+ISCSI_ERR - generic error code.
+
+.TP     
+.B
+2
+ISCSI_ERR_SESS_NOT_FOUND - session could not be found.
+
+.TP
+.B
+3
+ISCSI_ERR_NOMEM - could not allocate resource for operation.
+.TP
+.B
+4
+ISCSI_ERR_TRANS - connect problem caused operation to fail.
+
+.TP
+.B
+5
+ISCSI_ERR_LOGIN - generic iSCSI login failure.
+
+.TP
+.B
+6
+ISCSI_ERR_IDBM - error accessing/managing iSCSI DB.
+
+.TP
+.B
+7
+ISCSI_ERR_INVAL - invalid argument.
+
+.TP
+.B
+8
+ISCSI_ERR_TRANS_TIMEOUT - connection timer exired while trying to connect.
+
+.TP
+.B
+9
+ISCSI_ERR_INTERNAL - generic internal iscsid/kernel failure.
+
+.TP
+.B
+10
+ISCSI_ERR_LOGOUT - iSCSI logout failed.
+
+.TP
+.B
+11
+ISCSI_ERR_PDU_TIMEOUT - iSCSI PDU timedout.
+
+.TP
+.B
+12
+ISCSI_ERR_TRANS_NOT_FOUND - iSCSI transport module not loaded in kernel or iscsid.
+
+.TP
+.B
+13
+ISCSI_ERR_ACCESS - did not have proper OS permissions to access iscsid or execute iscsiadm command.
+
+.TP
+.B
+14
+ISCSI_ERR_TRANS_CAPS - transport module did not support operation.
+
+.TP
+.B
+15
+ISCSI_ERR_SESS_EXISTS - session is logged in.
+
+.TP
+.B
+16
+ISCSI_ERR_INVALID_MGMT_REQ - invalid IPC MGMT request.
+
+.TP
+.B
+17
+ISCSI_ERR_ISNS_UNAVAILABLE - iSNS service is not supported.
+
+.TP
+.B
+18
+ISCSI_ERR_ISCSID_COMM_ERR - a read/write to iscsid failed.
+
+.TP
+.B
+19
+ISCSI_ERR_FATAL_LOGIN - fatal iSCSI login error.
+
+.TP
+.B
+20
+ISCSI_ERR_ISCSID_NOTCONN - could ont connect to iscsid.
+
+.TP
+.B
+21
+ISCSI_ERR_NO_OBJS_FOUND - no records/targets/sessions/portals found to execute operation on.
+
+.TP
+.B
+22
+ISCSI_ERR_SYSFS_LOOKUP - could not lookup object in sysfs.
+
+.TP
+.B
+23
+ISCSI_ERR_HOST_NOT_FOUND - could not lookup host.
+
+.TP
+.B
+24
+ISCSI_ERR_LOGIN_AUTH_FAILED - login failed due to authorization failure.
+
+.TP
+.B
+25
+ISCSI_ERR_ISNS_QUERY - iSNS query failure.
+
+.TP
+.B
+26
+ISCSI_ERR_ISNS_REG_FAILED - iSNS registration/deregistration failed.
+
+
 .SH EXAMPLES
 
 .nf
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/doc/iscsid.8 open-iscsi-2.0-872-rc4-bnx2i.sync/doc/iscsid.8
--- open-iscsi-2.0-872-rc4-bnx2i/doc/iscsid.8	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/doc/iscsid.8	2011-08-14 16:48:25.000000000 -0500
@@ -35,6 +35,9 @@ run under user ID \fIuid\fR (default is 
 .BI [-g|--gid=]\fIgid\fP
 run under user group ID \fIgid\fR (default is the current user group ID).
 .TP
+.BI [-n|--no-pid-file]\fP
+do not write a process ID file.
+.TP
 .BI [-p|--pid=]\fIpid\-file\fP
 write process ID to \fIpid\-file\fR rather than the default
 \fI/var/run/iscsid.pid\fR
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/etc/iface.example open-iscsi-2.0-872-rc4-bnx2i.sync/etc/iface.example
--- open-iscsi-2.0-872-rc4-bnx2i/etc/iface.example	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/etc/iface.example	2011-08-14 16:48:25.000000000 -0500
@@ -60,3 +60,138 @@
 #    the same subnet.
 # iface.net_ifacename = eth0
 # iface.ipaddress = 102.50.50.101
+
+# OPTIONAL: iface.bootproto
+#
+# Valid values are:
+# "dhcp" and "static"
+#
+# REQUIRED when IPv4 address need to be obtained dynamically using DHCP
+# example:
+# iface.bootproto = dhcp
+#
+# OPTIONAL when the IPv4 address is set statically
+# example:
+# iface.ipaddress = 102.50.50.101
+# iface.bootproto = static
+#
+
+# OPTIONAL: iface.vlan_id
+# Used to set the VLAN ID for the iSCSI interfae.
+# example
+# iface.vlan_id = 1022
+
+# OPTIONAL: iface.vlan_priority
+# Used to set the VLAN priority for the iSCSI interfae.
+# example
+# iface.vlan_priority = 1
+
+# OPTIONAL: iface.vlan_state
+# Used to enable or disable the VLAN on the iSCSI interface
+# example
+# iface.vlan_state = enable
+
+# OPTIONAL: iface.ipv6_linklocal
+# Specify the IPV6 Link Local Address with the
+# link local prefix of FE80::0/64
+# example:
+# iface.ipv6_linklocal = fe80:0000:0000:0000:020e:1eff:1111:2221
+
+# OPTIONAL: iface.ipv6_router
+# Used to set a default IPV6 router
+# example:
+# iface.ipv6_router = fe80:0000:0000:0000:7ae7:d1ff:fe72:4048
+
+# OPTIONAL: iface.ipv6_autocfg
+# Used to set the discovery protocol to obtain IPV6 address
+# For example qla4xxx support neighbor discovery
+# example:
+# iface.ipv6_autocfg = nd
+
+# OPTIONAL: iface.linklocal_autocfg
+# For transport like qla4xxx this allows to auto configure the
+# IPV6 link local address based on the MAC address of the iSCSI
+# interface
+
+# OPTIONAL: iface.router_autocfg
+# Required to set the IPv6 router discovery protocol
+# To set the  router discovery  protocol to Neighbor Discovery specify "nd"
+# example:
+# iface.router_autocfg = nd
+
+# OPTIONAL: iface.state
+# By default the iface is enabled
+# iface.state = enable
+# To disable the iface set the state to "disable"
+# iface.state = disable
+
+# iface.iface_num
+# REQUIRED: When there are more than 1 interface to be configured.
+# For transports like qla4xxx, one can specify two IPV6 interfaces
+# in such case the iface_num must be set correctly
+# example:
+# iface settings for first IPV6 interface
+# iface.iscsi_ifacename = iface-qla4xxx-ipv6-1
+# iface.iface_num = 0
+#
+# iface settings for second IPV6 interface
+# iface.iscsi_ifacename = iface-qla4xxx-ipv6-2
+# iface.iface_num = 1
+
+# Here are some example iface files
+# IPV4 sample config file with static IP address:
+# BEGIN RECORD 2.0-872
+# iface.iscsi_ifacename = qla4xxx-3
+# iface.ipaddress = 192.168.1.75
+# iface.hwaddress = 00:0e:1e:04:93:92
+# iface.transport_name = qla4xxx
+# iface.bootproto = static
+# iface.subnet_mask = 255.255.255.0
+# iface.gateway = 192.168.1.1
+# iface.state = enable
+# iface.vlan = <empty>
+# iface.iface_num = 0
+# END RECORD
+#
+# IPV6 sample config file with neighbor discovery:
+#  BEGIN RECORD 2.0-872
+# iface.iscsi_ifacename = qla4xxx-3-1
+# iface.ipaddress =
+# iface.hwaddress = 00:0e:1e:04:93:92
+# iface.transport_name = qla4xxx
+# iface.ipv6_autocfg = nd
+# iface.linklocal_autocfg = auto
+# iface.router_autocfg = nd
+# iface.ipv6_linklocal = fe80:0000:0000:0000:020e:1eff:1111:2221
+# iface.ipv6_router = auto
+# iface.state = enable
+# iface.vlan = <empty>
+# iface.iface_num = 0
+# END RECORD
+
+# Ipv4 sample config file (DHCP configuration):
+#  BEGIN RECORD 2.0-872
+# iface.iscsi_ifacename = qla4xxx-3
+# iface.hwaddress = 00:0e:1e:04:93:92
+# iface.transport_name = qla4xxx
+# iface.bootproto = dhcp
+# iface.state = enable
+# iface.vlan = <empty>
+# iface.iface_num = 0
+# END RECORD
+
+# Sample ipv6 config file(manual configured IPs):
+# BEGIN RECORD 2.0-872
+# iface.iscsi_ifacename = iface-new-file
+# iface.ipaddress = fec0:ce00:7014:0041:1111:2222:1e04:9392
+# iface.hwaddress = 00:0e:1e:04:93:92
+# iface.transport_name = qla4xxx
+# iface.ipv6_autocfg = <empty>
+# iface.linklocal_autocfg = <empty>
+# iface.router_autocfg = <empty>
+# iface.ipv6_linklocal = fe80:0000:0000:0000:0000:0000:1e04:9392
+# iface.ipv6_router = fe80:0000:0000:0000:7ae7:d1ff:fe72:4048
+# iface.state = enable
+# iface.vlan = <empty>
+# iface.iface_num = 0
+# END RECORD
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/etc/initd/boot.suse open-iscsi-2.0-872-rc4-bnx2i.sync/etc/initd/boot.suse
--- open-iscsi-2.0-872-rc4-bnx2i/etc/initd/boot.suse	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/etc/initd/boot.suse	2011-08-14 16:48:25.000000000 -0500
@@ -4,36 +4,37 @@
 #
 ### BEGIN INIT INFO
 # Provides:          iscsiboot
-# Required-Start:    boot.proc
-# Should-Start:
-# Required-Stop:     
+# Required-Start:
+# Should-Start:      boot.multipath
+# Required-Stop:
 # Should-Stop:
 # Default-Start:     B
 # Default-Stop:      
-# Short-Description: Starts the iSCSI initiator daemon
-#                    
+# Short-Description: iSCSI initiator daemon root-fs support
+# Description:       Starts the iSCSI initiator daemon if the
+#                    root-filesystem is on an iSCSI device
+#               
 ### END INIT INFO
 
 ISCSIADM=/sbin/iscsiadm
-PID_FILE=/var/run/iscsi.pid
 CONFIG_FILE=/etc/iscsid.conf
 DAEMON=/sbin/iscsid
-ARGS="-c $CONFIG_FILE -p $PID_FILE"
+ARGS="-c $CONFIG_FILE"
 
 # Source LSB init functions
 . /etc/rc.status
 
 #
-# This service is run right after booting. So all activated targets
-# must be enabled during mkinitrd run and thus should not be removed
-# when the open-iscsi service is stopped.
+# This service is run right after booting. So all targets activated
+# during mkinitrd run should not be removed when the open-iscsi
+# service is stopped.
 #
 iscsi_mark_root_nodes()
 {
     $ISCSIADM -m session 2> /dev/null | while read t num i target ; do
 	ip=${i%%:*}
-	STARTUP=`$ISCSIADM -m node -p $ip -T $target | grep "node.conn\[0\].startup" | cut -d' ' -f3`
-	if [ "$STARTUP" != "onboot" ] ; then
+	STARTUP=`$ISCSIADM -m node -p $ip -T $target 2> /dev/null | grep "node.conn\[0\].startup" | cut -d' ' -f3`
+	if [ "$STARTUP" -a "$STARTUP" != "onboot" ] ; then
 	    $ISCSIADM -m node -p $ip -T $target -o update -n node.conn[0].startup -v onboot
 	fi
     done
@@ -50,13 +51,12 @@ fi
 
 case "$1" in
     start)
-	[ ! -d /var/lib/open-iscsi ] && mkdir -p /var/lib/open-iscsi
 	echo -n "Starting iSCSI initiator for the root device: "
 	startproc $DAEMON $ARGS
 	rc_status -v
 	iscsi_mark_root_nodes
 	;;
-    stop)
+    stop|restart|reload)
 	rc_failed 0
 	;;
     status)
@@ -68,13 +68,8 @@ case "$1" in
 	    rc_status -v
 	fi
 	;;
-    restart)
-	$0 stop
-	sleep 1
-	$0 start
-	;;
     *)
-	echo "Usage: $0 {start|stop|status|restart}"
+	echo "Usage: $0 {start|stop|status|restart|reload}"
 	exit 1
 	;;
 esac
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/etc/initd/initd.suse open-iscsi-2.0-872-rc4-bnx2i.sync/etc/initd/initd.suse
--- open-iscsi-2.0-872-rc4-bnx2i/etc/initd/initd.suse	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/etc/initd/initd.suse	2011-08-14 16:48:25.000000000 -0500
@@ -5,20 +5,22 @@
 ### BEGIN INIT INFO
 # Provides:          iscsi
 # Required-Start:    $network
-# Should-Start:
-# Required-Stop:     
-# Should-Stop:
+# Should-Start:      iscsitarget multipathd
+# Required-Stop:     $network
+# Should-Stop:       multipathd
 # Default-Start:     3 5
 # Default-Stop:      
-# Short-Description: Starts and stops the iSCSI client initiator
-#                    
+# Short-Description: iSCSI initiator daemon
+# Description:       The iSCSI initator is used to create and
+#                    manage iSCSI connections to a iSCSI Target.
+#
 ### END INIT INFO
 
-PID_FILE=/var/run/iscsi.pid
 CONFIG_FILE=/etc/iscsi/iscsid.conf
 DAEMON=/sbin/iscsid
 ISCSIADM=/sbin/iscsiadm
-ARGS="-c $CONFIG_FILE -p $PID_FILE"
+BRCM_ISCSIUIO=/sbin/brcm_iscsiuio
+ARGS="-c $CONFIG_FILE -n"
 
 # Source LSB init functions
 . /etc/rc.status
@@ -26,66 +28,359 @@ ARGS="-c $CONFIG_FILE -p $PID_FILE"
 # Reset status of this service
 rc_reset
 
+DM_MAJOR=$(sed -n 's/\(.*\) device-mapper/\1/p' /proc/devices)
+
 iscsi_login_all_nodes()
 {
 	echo -n "Setting up iSCSI targets: "
 	$ISCSIADM -m node --loginall=automatic 2> /dev/null
-	if [ $? == 19 ] ; then
+	if [ $? == 21 ] ; then
 	    rc_failed 6
 	fi
 	rc_status -v
 }
 
-iscsi_logout_all_nodes()
+#
+# Try to load all required modules prior to startup
+#
+iscsi_load_transport_modules()
 {
-	echo -n "Closing all iSCSI connections: "
-	# Logout from all sessions marked automatic
-	if ! $ISCSIADM -m node --logoutall=automatic 2> /dev/null; then
-		if [ $? == 19 ] ; then
-		    RETVAL=6
-		else
-		    RETVAL=1
+    loaded=$(sed -n "/^iscsi_tcp/p" /proc/modules)
+    if [ -z "$loaded" ] ; then
+	modprobe iscsi_tcp
+	if [ $? = 0 ] ; then
+	    echo -n " tcp"
+	fi
+    fi
+
+    for iface in /etc/iscsi/ifaces/*; do
+	[ -f "$iface" ] || continue
+	[ "$iface" = "iface.example" ] && continue
+	# Check if the iface has been configured
+	result=$(sed '/#.*/D;/iface.iscsi_ifacename/D;/iface.hwaddress/D;/iface.transport_name/D' $iface)
+	if [ "$result" ] ; then
+	    mod=$(sed -n 's/iface.transport_name *= *\(.*\)/\1/p' $iface)
+	    loaded=$(sed -n "/^$mod/p" /proc/modules)
+	    if [ -z "$loaded" ] ; then
+		modprobe $mod
+		if [ $? = 0 ] ; then
+		    echo -n " $mod"
 		fi
-		rc_failed $RETVAL
+	    fi
 	fi
-	rc_status -v
+    done
+}
 
-	# Not sure whether this is still needed
-	sleep 1
-	return ${RETVAL:-0}
+#
+# Set a temporary startmode for ifdown
+#
+iscsi_modify_if_startmode()
+{
+    local ifname=$1
+    local tmp_ifcfg=/dev/.sysconfig/network/if-$ifname
+
+    if [ -e "$tmp_ifcfg" ] ; then
+	. $tmp_ifcfg
+	if [ "$startmode" ] ; then
+	    return
+	fi
+    fi
+    : disabling shutdown on $ifname
+    echo "startmode=nfsroot" >> $tmp_ifcfg
 }
 
-iscsi_umount_all_luns()
+iscsi_get_ifacename_from_session()
 {
-    local d m dev p s
+    local session=$1
+    local ifacename
 
-    cat /proc/mounts | sed -ne '/^\/dev\/.*/p' | while read d m t o x; do 
-	if [ "$m" = "/" ] ; then 
-	    continue;
+    ifacename=$(iscsiadm -m session -r ${session##.*/session} 2> /dev/null | \
+	sed -n 's/iface.iscsi_ifacename = \(.*\)/\1/p')
+    if [ -z "$ifacename" ] ; then
+	# Check for iBFT
+	ifacename=$(iscsiadm -m fw 2> /dev/null)
+	if [ -n "$ifacename" ] ; then
+	    ifacename="fw"
 	fi
+    fi
+    echo $ifacename
+}
+
+iscsi_get_hwaddress_from_iface()
+{
+    local iface=$1
+    local hwaddress
+
+    hwaddress=$(iscsiadm -m iface -I "$iface" 2> /dev/null | sed -n 's/iface.hwaddress = \(.*\)/\1/p')
+    [ "$hwaddress" = "<empty>" ] && hwaddress=
+
+    echo $hwaddress
+}
+
+iscsi_get_ifname_from_iface()
+{
+    local iface=$1
+    local ifname
+
+    ifname=$(iscsiadm -m iface -I "$iface" 2> /dev/null | sed -n 's/iface.net_ifacename = \(.*\)/\1/p')
+    [ "$ifname" = "<empty>" ] && ifname=
+
+    echo $ifname
+}
+
+iscsi_get_ipaddr_from_iface()
+{
+    local iface=$1
+    local ipaddr
+
+    ipaddr=$(iscsiadm -m iface -I "$iface" 2> /dev/null | sed -n 's/iface.ipaddress = \(.*\)/\1/p')
+    [ "$ipaddr" = "<empty>" ] && ipaddr=
+
+    echo $ipaddr
+}
+
+iscsi_get_ifname_from_firmware()
+{
+    local hwaddress
+
+    hwaddress=$(iscsiadm -m fw 2> /dev/null | sed -n 's/iface.net_ifacename = \(.*\)/\1/p')
+
+    echo $hwaddress
+}
+
+#
+# cxgb3i is using the HWAddress to select
+# the correct interface
+#
+iscsi_get_ifname_from_hwaddress()
+{
+    local hwaddress=$1
+
+    for if in /sys/class/net/*; do
+	[ -e "$if" ] || continue
+	read mac < $if/address
+	[ "$mac" = "$hwaddress" ] || continue
+	echo ${if##*/}
+	break
+    done
+}
+
+iscsi_get_ifname_from_ipaddr()
+{
+    local ipaddr=$1
+    local ifname
+
+    ifname=$(ip addr show to $ipaddr | sed -n 's/[0-9]*: \([^ :]*\): .*/\1/p')
+    return $ifname
+}
+
+#
+# Handle 'default' interface:
+# It is basically impossible to determine via which
+# interface the iSCSI traffic will flow, so we take
+# the easy option and ignore _all_ active interfaces
+# during shutdown
+#
+iscsi_modify_all_interfaces()
+{
+    ip link show up | sed -n '/.*LOOPBACK.*/d;s/[0-9]*: \(.*\): .*/\1/p' | while read ifname; do
+	iscsi_modify_if_startmode $ifname
+    done
+}
+
+#
+# Check iface setting and disable
+# affected network interfaces
+#
+iscsi_check_interface()
+{
+    local session=$1
+    local i h n
+
+    i=$(iscsi_get_ifacename_from_session $session)
+    [ -z "$i" ] && continue
+    if [ "$i" = "default" ] ; then
+	iscsi_modify_all_interfaces
+    elif [ "$i" = "fw" ] ; then
+	n=$(iscsi_get_ifname_from_firmware)
+    else
+	n=$(iscsi_get_ifname_from_iface $i)
+	if [ -z "$n" ] ; then
+	    h=$(iscsi_get_hwaddress_from_iface $i)
+	    if [ -n "$h" ] ; then
+		n=$(iscsi_get_ifname_from_hwaddress $h)
+	    fi
+	fi
+	if [ -z "$n" ] ; then
+	    h=$(iscsi_get_ipaddr_from_iface $i)
+	    if [ -n "$h" ] ; then
+		n=$(iscsi_get_ifname_from_ipaddr $h)
+	    fi
+	fi
+    fi
+    if [ "$n" ] ; then
+	iscsi_modify_if_startmode $n
+    fi
+}
+
+#
+# Check if device 'dev' is mounted
+# Returns the mount point on success
+#
+iscsi_check_if_mounted()
+{
+    local dev=$1
+    local d m t o x p
+
+    cat /proc/mounts | sed -ne '/^\/dev\/.*/p' | while read d m t o x; do 
 	if [ -L "$d" ] ; then
 	    d=$(readlink -f $d)
 	fi
-	dev=${d##/dev}
+	[ -b "$d" ] || continue
+
+	b=$(ls -l $d | sed -n 's/.* \([0-9]*\), \([0-9]*\) .*/\1:\2/p')
+	p=$(cd -P /sys/dev/block/$b ; echo $PWD)
+
+	if [ -z "$p" ] ; then
+	    d=${d##/dev}
+	    p="/sys/block${d%%[0-9]*}"
+	fi
+
+	[ ! -d ${p} ] && continue
+
+	if [ -e $p/partition ] ; then
+	    p=$(cd -P $p/../; echo $PWD)
+	fi
+	if [ "$dev" = "${p##*/}" ] ; then
+	    echo $m
+	fi
+    done
+}
+
+#
+# Unwind block device stack
+# 
+# Stops unwinding if either no more 'holders'
+# are found or if a device is mounted
+# 
+# Unmounts top-level device and deconfigures
+# all devices down the stack
+#
+# Root fs is not unmounted
+#
+iscsi_unwind_stack()
+{
+    local p=$1
+    local d=${p##*/}
+    local u
+    local m
+
+    if [ ! -d ${p} ] ; then
+	return;
+    fi
+
+    m=$(iscsi_check_if_mounted $d)
+    if [ -z "$m" ] ; then
+	for s in $p/holders/* ; do
+	    [ -e $s ] || continue
+	    p=$(cd -P $s; echo $PWD)
+	    u=$(iscsi_unwind_stack $p)
+	    if [ "$u" ] ; then
+		echo -n "$u "
+	    fi
+	done
+    else
+	if [ "$m" = "/" ] ; then
+	    echo -n "$d "
+	    return 1
+	fi
+	if ! umount $m ; then
+	    echo -n "$d "
+	    return 1
+	fi
+    fi
 
-	if [ "${dev##/sd}" = "$dev" ] ; then
-	    continue;
+    if [ "${d#dm-}" != "$d" ] ; then
+	if ! dmsetup remove -j $DM_MAJOR -m ${d#dm-} 2> /dev/null ; then
+	    echo -n "$d "
+	    return 1
 	fi
-	p="/sys/block${dev%%[0-9]*}"
+    fi
 
-	if [ ! -d ${p} ] && [ ! -d ${p}/device ] ; then
-	    continue;
+    if [ "${d#md}" != "$d" ] ; then
+	if ! mdadm --manage /dev/$d --stop 2> /dev/null ; then
+	    echo -n "$d "
+	    return 1
 	fi
+    fi
+    return 0
+}
+
+#
+# Return all targets for a given session
+#
+iscsi_get_target()
+{
+    local session=$1
+    local d
+
+    for d in $session/device/target* ; do
+	[ -e "$d" ] || continue
+	echo "$d"
+    done
+}
+
+#
+# Checks all devices presented by a target
+# and tries to umount them.
+# Skip unmounting for the root fs.
+# Stops on the first device which could not be unmounted
+# and returns the mount device of that device.
+#
+iscsi_check_target()
+{
+    local t=$1
+    local d b m
 
-	s=$(cd -P ${p}/device && echo $PWD)
+    for d in $t/* ; do
+	[ -d $d/block ] || continue
+	for b in $d/block/sd* ; do
+	    [ -d "$b" ] || continue
+	    m=$(iscsi_unwind_stack $b)
+	    if [ -n "$m" ] ; then
+		echo $m
+		return 1
+	    fi
+	done
+    done
+}
 
-	case "$s" in
-	    */session[0-9]*/*)
-		# This is an iSCSI device
-		umount "$m"
-	    ;;
-	esac
+#
+# Check all sessions for mounted devices
+# and shutdown the session if the affected
+# devices could be umounted cleanly.
+# If umount fails disable shutdown on all
+# affected network interfaces
+#
+iscsi_stop_sessions()
+{
+    local t m s i
+
+    i=0
+    for session in /sys/class/iscsi_session/session* ; do
+	[ -e "$session" ] || continue;
+	[ -e $session/device ] || continue
+	t=$(iscsi_get_target $session)
+	m=$(iscsi_check_target $t)
+	s=${session##*/session}
+	if [ -z "$m" ] ; then
+	    iscsiadm -m session -r ${s} -u
+	    i=$(( $i + 1 ))
+	else
+	    iscsi_check_interface $s
+	fi
     done
+    echo $i
 }
 
 iscsi_list_all_nodes()
@@ -101,84 +396,45 @@ iscsi_list_all_nodes()
     done
 }
 
-iscsi_discover_all_targets()
-{
-	# Strip off any existing ID information
-	RAW_NODE_LIST=`iscsiadm -m node | sed -nre 's/^(\[[0-9a-f]*\] )?(.*)$/\2/p'`
-	# Obtain IPv4 list
-	IPV4_NODE_LIST=`echo "$RAW_NODE_LIST" | sed -nre 's/^([0-9]{1,3}(\.[0-9]{1,3}){3}):[^: ]* (.*)$/\1 \3/p'`
-	# Now obtain IPv6 list
-	IPV6_NODE_LIST=`echo "$RAW_NODE_LIST" | sed -nre 's/^([0-9a-f]{1,4}(:[0-9a-f]{0,4}){6}:[0-9a-f]{1,4}):[^: ]* (.*)$/\1 \3/p'`
-
-	DISC_TARGETS=""
-	while read NODE_ADDR NODE_NAME; do
-		[ -z "$NODE_ADDR" -a -z "$NODE_NAME" ] && continue
-		NODE_ATTRS=`iscsiadm -m node -p "$NODE_ADDR" -T "$NODE_NAME"`
-		NODE_STATUS=`echo "$NODE_ATTRS" | sed -nre 's/^.*node\.conn\[0\]\.startup = ([a-z]*).*$/\1/p'`
-
-		if [ "$NODE_STATUS" == 'automatic' ]; then
-			DISC_TARGETS=`echo "$DISC_TARGETS" | sed -re '/'"$NODE_ADDR"'/!{s/(.*)/\1 '"$NODE_ADDR"'/}'`
-		fi
-	done < <(echo "$IPV4_NODE_LIST"; echo "$IPV6_NODE_LIST")
-
-	for TARGET_ADDR in $DISC_TARGETS; do
-		echo -n "Attempting discovery on target at ${TARGET_ADDR}: "
-		iscsiadm -m discovery -t st -p "$TARGET_ADDR" > /dev/null 2>&1
-		if [ "$?" -ne 0 ]; then
-			rc_failed 1
-			rc_status -v
-			return 1
-		fi
-		rc_status -v
-	done
-}
-
 case "$1" in
     start)
-	[ ! -d /var/lib/iscsi ] && mkdir -p /var/lib/iscsi
 	if checkproc $DAEMON ; then
 	    RETVAL=0
 	else
 	    echo -n "Starting iSCSI initiator service: "
-	    modprobe iscsi_tcp
-	    modprobe -q ib_iser
+	    iscsi_load_transport_modules
+	    if grep -q bnx2i /proc/modules && [ -x $BRCM_ISCSIUIO ] ; then
+		startproc $BRCM_ISCSIUIO
+	    fi
 	    startproc $DAEMON $ARGS
 	    RETVAL=$?
 	    rc_status -v
 	fi
 	if [ "$RETVAL" == "0" ]; then
-	    iscsi_discover_all_targets
-	    RETVAL=$?
-	fi
-	if [ "$RETVAL" == "0" ]; then
 	    iscsi_login_all_nodes
 	fi
 	;;
     stop)
-	iscsi_umount_all_luns
-	if iscsi_logout_all_nodes ; then
-	    iscsiadm -k 0
-	    RETVAL=$?
-	else
-	    RETVAL=1
-	fi
+	n=$(iscsi_stop_sessions)
 	echo -n "Stopping iSCSI initiator service: "
-	if [ "$RETVAL" == "0" ]; then
-	    rm -f $PID_FILE
-	    status=0
-	    modprobe -r iscsi_tcp
-	    if [ "$?" -ne "0" -a "$?" -ne "1" ]; then
-	    	status=1
-	    fi
-	    modprobe -q -r ib_iser
-            if [ "$?" -ne "0" -a "$?" -ne "1" ]; then
-	        status=1 
-            fi
-	    rc_failed $status
-	else
+	if [ "$n" ] && [ "$n" != "0" ] ; then
+	    m=$(iscsiadm -m session 2> /dev/null)
+	    if [ -z "$m" ] ; then
+		killproc -KILL $DAEMON
+		RETVAL=$?
+		if grep -q bnx2i /proc/modules && [ -x $BRCM_ISCSIUIO ]; then
+		    killproc -KILL $BRCM_ISCSIUIO
+		fi
+ 		RETVAL=$?
+	    else
+		RETVAL=1
+	    fi
 	    rc_failed $RETVAL
+	    rc_status -v
+	else
+	    # umounting failed, leave initiator running
+	    rc_status -s
 	fi
-	rc_status -v
 	;;
     status)
 	echo -n "Checking for iSCSI initiator service: "
@@ -190,7 +446,7 @@ case "$1" in
 	    rc_status -v
 	fi
 	;;
-    restart)
+    restart|reload)
 	$0 stop
 	RETVAL=$?
 	if [ "$RETVAL" != "0" ]; then
@@ -201,7 +457,7 @@ case "$1" in
 	$0 start
 	;;
     *)
-	echo "Usage: $0 {start|stop|status|restart}"
+	echo "Usage: $0 {start|stop|status|restart|reload}"
 	exit 1
 	;;
 esac
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/etc/iscsid.conf open-iscsi-2.0-872-rc4-bnx2i.sync/etc/iscsid.conf
--- open-iscsi-2.0-872-rc4-bnx2i/etc/iscsid.conf	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/etc/iscsid.conf	2011-08-14 16:48:25.000000000 -0500
@@ -39,6 +39,10 @@ iscsid.startup = /sbin/iscsid
 # To manually startup the session set to "manual". The default is manual.
 node.startup = manual
 
+# For "automatic" startup nodes, setting this to "Yes" will try logins on each
+# available iface until one succeeds, and then stop.  The default "No" will try
+# logins on all availble ifaces simultaneously.
+node.leading_login = No
 
 # *************
 # CHAP Settings
@@ -278,6 +282,11 @@ discovery.sendtargets.iscsi.MaxRecvDataS
 # The default is to never use DataDigests or HeaderDigests.
 #
 
+# For multipath configurations, you may want more than one session to be
+# created on each iface record.  If node.session.nr_sessions is greater
+# than 1, performing a 'login' for that node will ensure that the
+# appropriate number of sessions is created.
+node.session.nr_sessions = 1
 
 #************
 # Workarounds
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/include/iscsi_err.h open-iscsi-2.0-872-rc4-bnx2i.sync/include/iscsi_err.h
--- open-iscsi-2.0-872-rc4-bnx2i/include/iscsi_err.h	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/include/iscsi_err.h	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,69 @@
+/*
+ * Return codes used by iSCSI tools.
+ */
+#ifndef _ISCSI_ERR_
+#define _ISCSI_ERR_
+
+enum {
+	ISCSI_SUCCESS			= 0,
+	/* Generic error */
+	ISCSI_ERR			= 1,
+	/* session could not be found */
+	ISCSI_ERR_SESS_NOT_FOUND	= 2,
+	/* Could not allocate resource for operation */
+	ISCSI_ERR_NOMEM			= 3,
+	/* Transport error caused operation to fail */
+	ISCSI_ERR_TRANS			= 4,
+	/* Generic login failure */
+	ISCSI_ERR_LOGIN			= 5,
+	/* Error accessing/managing iSCSI DB */
+	ISCSI_ERR_IDBM			= 6,
+	/* Invalid argument */
+	ISCSI_ERR_INVAL			= 7,
+	/* Connection timer exired while trying to connect */
+	ISCSI_ERR_TRANS_TIMEOUT		= 8,
+	/* Generic internal iscsid failure */
+	ISCSI_ERR_INTERNAL		= 9,
+	/* Logout failed */
+	ISCSI_ERR_LOGOUT		= 10,
+	/* iSCSI PDU timedout */
+	ISCSI_ERR_PDU_TIMEOUT		= 11,
+	/* iSCSI transport module not loaded in kernel or iscsid */
+	ISCSI_ERR_TRANS_NOT_FOUND	= 12,
+	/* Permission denied */
+	ISCSI_ERR_ACCESS		= 13,
+	/* Transport module did not support operation */
+	ISCSI_ERR_TRANS_CAPS		= 14,
+	/* Session is logged in */
+	ISCSI_ERR_SESS_EXISTS		= 15,
+	/* Invalid IPC MGMT request */
+	ISCSI_ERR_INVALID_MGMT_REQ	= 16,
+	/* iSNS service is not supported */
+	ISCSI_ERR_ISNS_UNAVAILABLE	= 17,
+	/* A read/write to iscsid failed */
+	ISCSI_ERR_ISCSID_COMM_ERR	= 18,
+	/* Fatal login error */
+	ISCSI_ERR_FATAL_LOGIN		= 19,
+	/* Could ont connect to iscsid */
+	ISCSI_ERR_ISCSID_NOTCONN	= 20,
+	/* No records/targets/sessions/portals found to execute operation on */
+	ISCSI_ERR_NO_OBJS_FOUND		= 21,
+	/* Could not lookup object in sysfs */
+	ISCSI_ERR_SYSFS_LOOKUP		= 22,
+	/* Could not lookup host */
+	ISCSI_ERR_HOST_NOT_FOUND	= 23,
+	/* Login failed due to authorization failure */
+	ISCSI_ERR_LOGIN_AUTH_FAILED	= 24,
+	/* iSNS query failure */
+	ISCSI_ERR_ISNS_QUERY		= 25,
+	/* iSNS registration/deregistration failed */
+	ISCSI_ERR_ISNS_REG_FAILED	= 26,
+
+	/* Always last. Indicates end of error code space */
+	ISCSI_MAX_ERR_VAL,
+} iscsi_err;
+
+extern void iscsi_err_print_msg(int err);
+extern char *iscsi_err_to_str(int err);
+
+#endif
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/include/iscsi_if.h open-iscsi-2.0-872-rc4-bnx2i.sync/include/iscsi_if.h
--- open-iscsi-2.0-872-rc4-bnx2i/include/iscsi_if.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/include/iscsi_if.h	2011-08-14 16:48:25.000000000 -0500
@@ -64,6 +64,9 @@ enum iscsi_uevent_e {
 	ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST	= UEVENT_BASE + 19,
 
 	ISCSI_UEVENT_PATH_UPDATE	= UEVENT_BASE + 20,
+	ISCSI_UEVENT_SET_IFACE_PARAMS	= UEVENT_BASE + 21,
+
+	ISCSI_UEVENT_MAX		= ISCSI_UEVENT_SET_IFACE_PARAMS,
 
 	/* up events */
 	ISCSI_KEVENT_RECV_PDU		= KEVENT_BASE + 1,
@@ -75,6 +78,9 @@ enum iscsi_uevent_e {
 
 	ISCSI_KEVENT_PATH_REQ		= KEVENT_BASE + 7,
 	ISCSI_KEVENT_IF_DOWN		= KEVENT_BASE + 8,
+	ISCSI_KEVENT_CONN_LOGIN_STATE   = KEVENT_BASE + 9,
+
+	ISCSI_KEVENT_MAX		= ISCSI_KEVENT_CONN_LOGIN_STATE,
 };
 
 enum iscsi_tgt_dscvr {
@@ -177,6 +183,10 @@ struct iscsi_uevent {
 		struct msg_set_path {
 			uint32_t	host_no;
 		} set_path;
+		struct msg_set_iface_params {
+			uint32_t	host_no;
+			uint32_t	count;
+		} set_iface_params;
 	} u;
 	union {
 		/* messages k -> u */
@@ -198,6 +208,11 @@ struct iscsi_uevent {
 			uint32_t	cid;
 			uint64_t	recv_handle;
 		} recv_req;
+		struct msg_conn_login {
+			uint32_t	sid;
+			uint32_t	cid;
+			uint32_t	state; /* enum iscsi_conn_state */
+		} conn_login;
 		struct msg_conn_error {
 			uint32_t	sid;
 			uint32_t	cid;
@@ -219,6 +234,21 @@ struct iscsi_uevent {
 	} r;
 } __attribute__ ((aligned (sizeof(uint64_t))));
 
+enum iscsi_param_type {
+	ISCSI_PARAM,		/* iscsi_param (session, conn, target, LU) */
+	ISCSI_HOST_PARAM,	/* iscsi_host_param */
+	ISCSI_NET_PARAM,	/* iscsi_net_param */
+};
+
+struct iscsi_iface_param_info {
+	uint32_t iface_num;	/* iface number, 0 - n */
+	uint32_t len;		/* Actual length of the param */
+	uint16_t param;		/* iscsi param value */
+	uint8_t iface_type;	/* IPv4 or IPv6 */
+	uint8_t param_type;	/* iscsi_param_type */
+	uint8_t value[0];	/* length sized value follows */
+} __packed;
+
 /*
  * To keep the struct iscsi_uevent size the same for userspace code
  * compatibility, the main structure for ISCSI_UEVENT_PATH_UPDATE and
@@ -242,6 +272,70 @@ struct iscsi_path {
 	uint16_t	pmtu;
 } __attribute__ ((aligned (sizeof(uint64_t))));
 
+/* iscsi iface enabled/disabled setting */
+#define ISCSI_IFACE_DISABLE	0x01
+#define ISCSI_IFACE_ENABLE	0x02
+
+/* ipv4 bootproto */
+#define ISCSI_BOOTPROTO_STATIC		0x01
+#define ISCSI_BOOTPROTO_DHCP		0x02
+
+/* ipv6 addr autoconfig type */
+#define ISCSI_IPV6_AUTOCFG_DISABLE		0x01
+#define ISCSI_IPV6_AUTOCFG_ND_ENABLE		0x02
+#define ISCSI_IPV6_AUTOCFG_DHCPV6_ENABLE	0x03
+
+/* ipv6 link local addr type */
+#define ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE	0x01
+#define ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE	0x02
+
+/* ipv6 router addr type */
+#define ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE	0x01
+#define ISCSI_IPV6_ROUTER_AUTOCFG_DISABLE	0x02
+
+#define ISCSI_IFACE_TYPE_IPV4		0x01
+#define ISCSI_IFACE_TYPE_IPV6		0x02
+
+#define ISCSI_MAX_VLAN_ID		4095
+#define ISCSI_MAX_VLAN_PRIORITY		7
+
+/* iscsi vlan enable/disabled setting */
+#define ISCSI_VLAN_DISABLE	0x01
+#define ISCSI_VLAN_ENABLE	0x02
+
+/* iSCSI network params */
+enum iscsi_net_param {
+	ISCSI_NET_PARAM_IPV4_ADDR		= 1,
+	ISCSI_NET_PARAM_IPV4_SUBNET		= 2,
+	ISCSI_NET_PARAM_IPV4_GW			= 3,
+	ISCSI_NET_PARAM_IPV4_BOOTPROTO		= 4,
+	ISCSI_NET_PARAM_MAC			= 5,
+	ISCSI_NET_PARAM_IPV6_LINKLOCAL		= 6,
+	ISCSI_NET_PARAM_IPV6_ADDR		= 7,
+	ISCSI_NET_PARAM_IPV6_ROUTER		= 8,
+	ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG	= 9,
+	ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG	= 10,
+	ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG	= 11,
+	ISCSI_NET_PARAM_IFACE_ENABLE		= 12,
+	ISCSI_NET_PARAM_VLAN_ID			= 13,
+	ISCSI_NET_PARAM_VLAN_PRIORITY		= 14,
+	ISCSI_NET_PARAM_VLAN_ENABLED		= 15,
+	ISCSI_NET_PARAM_IFACE_TYPE		= 16,
+	ISCSI_NET_PARAM_IFACE_NAME		= 17,
+	ISCSI_NET_PARAM_MTU			= 18,
+	ISCSI_NET_PARAM_PORT			= 19,
+};
+
+enum iscsi_conn_state {
+	ISCSI_CONN_STATE_FREE,
+	ISCSI_CONN_STATE_XPT_WAIT,
+	ISCSI_CONN_STATE_IN_LOGIN,
+	ISCSI_CONN_STATE_LOGGED_IN,
+	ISCSI_CONN_STATE_IN_LOGOUT,
+	ISCSI_CONN_STATE_LOGOUT_REQUESTED,
+	ISCSI_CONN_STATE_CLEANUP_WAIT,
+};
+
 /*
  * Common error codes
  */
@@ -268,6 +362,7 @@ enum iscsi_err {
 	ISCSI_ERR_INVALID_HOST		= ISCSI_ERR_BASE + 18,
 	ISCSI_ERR_XMIT_FAILED		= ISCSI_ERR_BASE + 19,
 	ISCSI_ERR_TCP_CONN_CLOSE	= ISCSI_ERR_BASE + 20,
+	ISCSI_ERR_SCSI_EH_SESSION_RST	= ISCSI_ERR_BASE + 21,
 };
 
 /*
@@ -296,7 +391,7 @@ enum iscsi_param {
 	ISCSI_PARAM_PERSISTENT_PORT,
 	ISCSI_PARAM_SESS_RECOVERY_TMO,
 
-	/* pased in through bind conn using transport_fd */
+	/* passed in through bind conn using transport_fd */
 	ISCSI_PARAM_CONN_PORT,
 	ISCSI_PARAM_CONN_ADDRESS,
 
@@ -318,6 +413,7 @@ enum iscsi_param {
 	ISCSI_PARAM_INITIATOR_NAME,
 
 	ISCSI_PARAM_TGT_RESET_TMO,
+	ISCSI_PARAM_TARGET_ALIAS,
 	/* must always be last */
 	ISCSI_PARAM_MAX,
 };
@@ -358,6 +454,7 @@ enum iscsi_param {
 #define ISCSI_ISID			(1ULL << ISCSI_PARAM_ISID)
 #define ISCSI_INITIATOR_NAME		(1ULL << ISCSI_PARAM_INITIATOR_NAME)
 #define ISCSI_TGT_RESET_TMO		(1ULL << ISCSI_PARAM_TGT_RESET_TMO)
+#define ISCSI_TARGET_ALIAS		(1ULL << ISCSI_PARAM_TARGET_ALIAS)
 
 /* iSCSI HBA params */
 enum iscsi_host_param {
@@ -394,6 +491,7 @@ enum iscsi_host_param {
 #define CAP_DIGEST_OFFLOAD	0x1000	/* offload hdr and data digests */
 #define CAP_PADDING_OFFLOAD	0x2000	/* offload padding insertion, removal,
 					 and verification */
+#define CAP_LOGIN_OFFLOAD	0x4000  /* offload normal session login */
 
 /*
  * These flags describes reason of stop_conn() call
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/Makefile open-iscsi-2.0-872-rc4-bnx2i.sync/Makefile
--- open-iscsi-2.0-872-rc4-bnx2i/Makefile	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/Makefile	2011-08-14 16:48:25.000000000 -0500
@@ -24,10 +24,10 @@ IFACEFILES = etc/iface.example
 # using '$(MAKE)' instead of just 'make' allows make to run in parallel
 # over multiple makefile.
 
-all: user kernel
+all: user
 
 user: ;
-	cd utils/open-isns; ./configure; $(MAKE)
+	cd utils/open-isns; ./configure --with-security=no; $(MAKE)
 	$(MAKE) -C utils/sysdeps
 	$(MAKE) -C utils/fwparam_ibft
 	$(MAKE) -C usr
@@ -68,7 +68,7 @@ clean:
 	install_initd_suse install_initd_redhat install_initd_debian \
 	install_etc install_iface install_doc install_kernel install_iname
 
-install: install_kernel install_programs install_doc install_etc \
+install: install_programs install_doc install_etc \
 	install_initd install_iname install_iface
 
 install_user: install_programs install_doc install_etc \
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/README open-iscsi-2.0-872-rc4-bnx2i.sync/README
--- open-iscsi-2.0-872-rc4-bnx2i/README	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/README	2011-08-14 16:48:25.000000000 -0500
@@ -371,9 +371,10 @@ Usage: iscsiadm [OPTION]
 			  iscsi_ifacename.
 
 			  See below for examples.
-  -m host --host=hostno --print=level
-			  Display information for a specific host if hostno
-			  is passed in. If no hostno is passed in then info
+  -m host --host=hostno|MAC --print=level
+			  Display information for a specific host. The host
+			  can be passed in by host number or by MAC address.
+			  If a host is not passed in then info
 			  for all hosts is printed.
 
 			  Print level can be 0 to 4.
@@ -408,8 +409,9 @@ this the following is not needed for sof
 Warning!!!!!!
 This feature is experimental. The interface may change. When reporting
 bugs, if you cannot do a "ping -I ethX target_portal", then check your
-network settings first. If you cannot ping the portal, then you will
-not be able to bind a session to a NIC.
+network settings first. Make sure the rp_filter setting is set to 0 or 2
+(see Prep section below for more info). If you cannot ping the portal,
+then you will not be able to bind a session to a NIC.
 
 What is a scsi_host and iface for software, hardware and partial
 offload iscsi?
@@ -427,6 +429,32 @@ structure. For each HBA port or for soft
 device (ethX) or NIC, that you wish to bind sessions to you must create
 a iface config /etc/iscsi/ifaces.
 
+Prep:
+
+The iface binding feature requires the sysctl setting
+net.ipv4.conf.default.rp_filter to be set to 0 or 2. This can be set
+in /etc/sysctl.conf by having the line:
+
+net.ipv4.conf.default.rp_filter = N
+
+where N is 0 or 2. Note that when setting this you may have to reboot
+the box for the value to take effect.
+
+
+rp_filter information from Documentation/networking/ip-sysctl.txt:
+
+rp_filter - INTEGER
+        0 - No source validation.
+        1 - Strict mode as defined in RFC3704 Strict Reverse Path
+            Each incoming packet is tested against the FIB and if the interface
+            is not the best reverse path the packet check will fail.
+            By default failed packets are discarded.
+        2 - Loose mode as defined in RFC3704 Loose Reverse Path
+            Each incoming packet's source address is also tested against the FIB
+            and if the source address is not reachable via any interface
+            the packet check will fail.
+
+
 Running:
 
 # iscsiadm -m iface
@@ -488,10 +516,10 @@ some helpful management commands.
 5.1.2 Setting up a iface for a iSCSI offload card
 =================================================
 
-This section describes how to setup ifaces for use with Chelsio
-and Broadcom cards.
+This section describes how to setup ifaces for use with Chelsio, Broadcom and
+QLogic cards.
 
-By default, iscsiadm will create a iface for each Broadcom and Chelsio
+By default, iscsiadm will create a iface for each Broadcom, QLogic and Chelsio
 port. The iface name will be of the form:
 
 $transport/driver_name.$MAC_ADDRESS
@@ -502,6 +530,7 @@ Running:
 default tcp,<empty>,<empty>,<empty>,<empty>
 iser iser,<empty>,<empty>,<empty>,<empty>
 cxgb3i.00:07:43:05:97:07 cxgb3i,00:07:43:05:97:07,<empty>,<empty>,<empty>
+qla4xxx.00:0e:1e:04:8b:2e qla4xxx,00:0e:1e:04:8b:2e,<empty>,<empty>,<empty>
 
 
 Will report iface configurations that are setup in /etc/iscsi/ifaces.
@@ -520,7 +549,7 @@ default one in /etc/iscsi/initiatorname.
 
 
 
-To display these values in a more friendly run:
+To display these values in a more friendly way, run:
 
 iscsiadm -m iface -I cxgb3i.00:07:43:05:97:07
 # BEGIN RECORD 2.0-871
@@ -544,6 +573,38 @@ For the name of the value we want to upd
 the "iscsiadm -m iface -I cxgb3i.00:07:43:05:97:07" command which is
 "iface.ipaddress".
 
+Note2.
+
+For QLogic ports after updating the iface record, for network settings to take
+effect, one must apply or applyall the settings.
+
+iscsiadm -m iface -I qla4xxx.00:0e:1e:04:8b:2e -o apply or
+iscsiadm -m iface -H 00:0e:1e:04:8b:2e -o applyall
+
+With operation "apply" network setting for the specified iface will take effect.
+With operation "applyall" network settings for all ifaces on a specific host
+will take take effect. The host can be specified using the -H/--host argument
+by either the MAC address of the host or the host number.
+
+
+Here is an example of setting multiple IPv6 address on single iSCSI interface
+port.
+First interface (no need to set iface_num, it is 0 by default)
+
+iscsiadm -m iface -I qla4xxx.00:0e:1e:04:8b:2a -o update \
+	 -n iface.ipaddress -v fec0:ce00:7014:0041:1111:2222:1e04:9392
+
+Create the second interface if it does not exist
+
+iscsiadm -m iface -I qla4xxx.00:0e:1e:04:8b:2a.1 -op=new
+iscsiadm -m iface -I qla4xxx.00:0e:1e:04:8b:2a -o update \
+	 -n iface.iface_num -v 1 (iface_num is mandatory for second iface)
+iscsiadm -m iface -I qla4xxx.00:0e:1e:04:8b:2a -o update \
+	 -n iface.ipaddress -v = fec0:ce00:7014:0041:1111:2222:1e04:9393
+iscsiadm -m iface -H 00:0e:1e:04:8b:2a --op=applyall
+
+Note: If there are common settings for multiple interfaces then the
+settings from 0th iface would be considered valid.
 
 Now, we can use this iface to login into targets, which is described in the
 next section.
@@ -624,6 +685,9 @@ To now log into targets it is the same a
 	If a record does not exist, it will be created using the iscsid.conf
 	discovery settings.
 
+	The argument to -p may also be a hostname instead of an address.
+	    ./iscsiadm -m discoverydb -t st -p smoehost --discover
+
 	For the ifaces, iscsiadm will first search /etc/iscsi/ifaces for
 	interfaces using software iscsi. If any are found then nodes found
 	during discovery will be setup so that they can logged in through
@@ -748,6 +812,10 @@ To now log into targets it is the same a
 	    ./iscsiadm -m node -T iqn.2005-03.com.max \
 				-p [2001:c90::211:9ff:feb8:a9e9]:3260 -l
 
+	To specify a hostname the following can be used:
+
+	    ./iscsiadm -m node -T iqn.2005-03.com.max -p somehost -l
+
     - iSCSI Login to a specific portal through the NIC setup as iface0:
 
 	    ./iscsiadm -m node -T iqn.2005-03.com.max -p 192.168.0.4:3260 \
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/TODO open-iscsi-2.0-872-rc4-bnx2i.sync/TODO
--- open-iscsi-2.0-872-rc4-bnx2i/TODO	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/TODO	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,404 @@
+iSCSI DEVELOPMENT HOWTO AND TODO
+--------------------------------
+July 7th 2011
+
+
+If you are admin or user and just want to send a fix, just send the fix any
+way you can. We can port the patch to the proper tree and fix up the patch
+for you. Engineers that would like to do more advanced development then the
+following guideline should be followed.
+
+Submitting Patches
+------------------
+Code should follow the Linux kernel codying style doc:
+http://www.kernel.org/doc/Documentation/CodingStyle
+
+Patches should be submitted to the open-iscsi list open-iscsi@googlegroups.com.
+They should be made with "git diff" or "diff -up" or "diff -uprN", and
+kernel patches must have a "Signed-off-by" line. See section 12
+http://www.kernel.org/doc/Documentation/SubmittingPatches for more
+information on the the signed off line.
+
+Getting the Code
+----------------
+Kernel patches should be made against the linux-2.6-iscsi tree. This can
+be downloaded from kernel.org with git with the following commands:
+
+git clone git://git.kernel.org/pub/scm/linux/kernel/git/mnc/linux-2.6-iscsi.git
+
+Userspace patches should be made against the open-iscsi git tree:
+
+git clone git://git.kernel.org/pub/scm/linux/kernel/git/mnc/open-iscsi.git
+
+
+
+KERNEL TODO ITEMS
+-----------------
+
+1. Make iSCSI log messages humanly readable. In many cases the iscsi tools
+and modules will log a error number value. The most well known is conn
+error 1011. Users should not have to search on google for what this means.
+
+We should:
+
+1. Write a simple table to convert the error values to a string and print
+them out.
+
+2. Document the values, how you commonly hit them and common solutions
+in the iSCSI docs.
+
+See scsi_transport_iscsi.c:iscsi_conn_error_event for where the evil
+"detected conn error 1011" is printed. See the enum iscsi_err in iscsi_if.h
+for a definition of the error code values.
+
+---------------------------------------------------------------------------
+
+2. Implement iSCSI dev loss support.
+
+Currently if a session is down for longer than replacement/recovery_timeout
+seconds, the iscsi layer will unblock the devices and fail IO. Other
+transport, like FC and SAS, will do something similar. FC has a
+fast_io_fail tmo which will unblock devices and fail IO, then it has a
+dev_loss_tmo which will delete the devices accessed through that port.
+
+iSCSI needs to implement dev_loss_tmo behavior, because apps are beginning
+to expect this behavior. An initial path was made here:
+http://groups.google.com/group/open-iscsi/msg/031510ab4cecccfd?dmode=source 
+
+Since all drivers want this behavior we want to make it common. We need to
+change the patch in that link to add a dev_loss_tmo handler callback to the
+scsi_transport_template struct, and add some common sysfs and helpers
+functions to manage the dev_loss_tmo variable.
+
+
+*Being worked on by Vikek S
+
+---------------------------------------------------------------------------
+
+3. Reduce locking contention between session lock.
+
+The session lock is basically one big lock that protects everything
+in the iscsi_session. This lock could be broken down into smaller locks
+and maybe even replaced with something that would not require a lock.
+
+For example:
+
+1. The session lock serializes access to the current R2T the initiator is
+handling (a R2T from the target or the initialR2T if being used). libiscsi/
+libiscsi_tcp will call iscsi_tcp_get_curr_r2t and grab the session lock in
+the xmit path from the xmit thread and then in the recv path
+libiscsi_tcp/iscsi_tcp will call iscsi_tcp_r2t_rsp (this function is called
+with the session lock held). We could add a new per iscsi_task lock and
+use that to gaurd the R2T.
+
+2. For iscsi_tcp and cxgb*i, libiscsi uses the session->cmdqueue linked list
+and the session lock to queue IO from the queuecommand function (run from
+scsi softirq or kblockd context) to the iscsi xmit thread. Once the task is
+sent from that thread, it is deleted from the list.
+
+It seems we should be able to remove the linked list use here. The tasks
+are all preallocated in the session->cmds array. We can access that
+array and check the task->state (see fail_scsi_tasks for an example).
+We just need to come up with a way to safely set the task state,
+wake the xmit thread and make sure that tasks are executed in the order
+that the scsi layer sent them to our queuecommand function.
+
+A starting point on the queueing:
+We might be able to create a workqueue per processor, queue the work,
+which in this case is the execution of the task, from the queuecommand,
+then rely on the work queue synchronization and serialization code.
+Not 100% sure about this.
+
+Alternative to changing the threading:
+Can we figure out a way to just remove the xmit thread? We currently
+cannot because the network may only be able to send 1000 bytes, but
+to send the current command we need to send 2000. We cannot sleep
+from the queuecommand context until another 1000 bytes frees up and for
+iscsi_tcp we cannot sleep from the recv conext (this happens because we
+could have got a R2T from target and are handling it from the recv path).
+
+
+Note: that for iser and offload drivers like bnx2i and be2iscsi their
+is no xmit thread used.
+
+Note2: cxgb*i does not actually need the xmit thread so a side project
+could be to convert that driver.
+
+
+---------------------------------------------------------------------------
+
+4. Make memory access more efficient on multi-processor machines.
+We are moving twords per process queues in the block layer, so it would
+be a good idea to move the iscsi structs to be allocated on a per process
+basis.
+
+---------------------------------------------------------------------------
+
+5. Make blk_iopoll support (see block/blk-iopoll.c and be2iscsi for an
+example) being able to round robin IO across processors or complete
+on the processor it was queued on
+(today it always completes the IO on the processor the softirq was raised on),
+and convert bnx2i, ib_iser and cxgb*i to it.
+
+Not sure if it will help iscsi_tcp and cxgb, because their completion is done
+from the network softirq which does polling already. With irq balancing it
+can also be spread over all processors too.
+
+---------------------------------------------------------------------------
+
+6. Replace iscsi_get_next_target_id with idr use.
+
+iscsi_tcp and ib_iser allocate a session per host, so the target_id is
+always just 0. The offload drivers allocate a host per pci resource, so they
+will have multiple sessions for each host. When a session is added,
+iscsi_add_session will try to find a target_id to use by looping over
+all the targets on the host. We could replace that loop with idr.
+
+
+* Being worked on by John Jose.
+
+---------------------------------------------------------------------------
+
+7. When userspace calls into the kernel using the iscsi netlink interface
+to execute oprations like creating/destroying a session, create a connection
+to a target, etc the rx_queue_mutex is held the entire time (see
+iscsi_if_rx for the iscsi netlink interface entry point). This means
+if the driver should block every thing will be held up.
+
+iscsi_tcp does not block, but some offload drivers might for a couple seconds
+to 10 or 15 secs while it figures out what is going on or cleans up. This a 
+major problem for things like multipath where one connection blocking up the
+recovery of every other connection will delay IO from re-flowing quickly.
+
+We should looking into breaking up the rx_queue_mutex into finer grained
+locks or making it multi threaded. For the latter we could queue operations
+into workqueues.
+
+---------------------------------------------------------------------------
+
+7. Add tracing support to iscsi modules. See the scsi layer's
+trace_scsi_dispatch_cmd_start for an example.
+
+Well, actually in general look into all the tracing stuff available
+(trace_printk/ftrace, etc) and use one.
+
+See http://lwn.net/Articles/291091/ for some details on what is out
+there. We can only use something that is upstream though.
+
+---------------------------------------------------------------------------
+
+8. Improve the iscsi driver logging. Each driver has a different
+way to control logging. We should unify them and make it managable
+by iscsiadm. So each driver would use a common format, there would
+be a common kernel interface to set the logging level, etc.
+
+---------------------------------------------------------------------------
+
+9. Implement more features from the iSCSI RFC if they are worth it.
+
+- Error Recovery Level (ERL) 1 support - will help tape support.
+- Multi R2T support - Might improve write performance.
+- OutOfOrder support - Might imrpove performance.
+
+---------------------------------------------------------------------------
+
+10. Add support for digest/CRC offload.
+
+---------------------------------------------------------------------------
+
+11. Finish intel IOAT support. I started this here:
+http://groups.google.com/group/open-iscsi/msg/2626b8606edbe690?dmode=source
+but could only test on boxes with 1 gig interfaces which showed no
+difference in performance. Intel had said they saw significant throughput
+gains when using 10 gig.
+
+---------------------------------------------------------------------------
+
+12. Remove the login buffer preallocated buffer. Storage drivers must be able
+to make forward process, so that they can always write out a page incase the
+kernel needs to allocate the page to another process. If the connection were
+to be disconnected and the initiator needed to relogin to the target at this
+time, we might not be abe to allocate a page for the login commands buffer.
+
+To work around the problem the initiator prealloctes a 8K (sometimes
+more depending on the page size) buffer for each session (see iscsi_conn_setup'
+s __get_free_pages call). This is obviously very wasteful since it will be
+a rate occurance. Can we think of a way to allow multiple sessions to
+be relogged in at the same time, but not have to preallocate so many
+buffers?
+
+---------------------------------------------------------------------------
+
+13. Support iSCSI over swap safely.
+
+Basically just need to hook iscsi_tcp into the patches that
+were submitted here for NBD.
+
+https://lwn.net/Articles/446831/
+
+
+---------------------------------------------------------------------------
+
+
+
+
+
+USERSPACE TODO ITEMS
+--------------------
+1. The iscsi tools, iscsid, iscsiadm and iscsid, have a debug flag, -d N, that
+allows the user to control the amount of output that is logged. The argument
+N is a integer from 1 to 8, with 8 printing out the most output.
+
+The problem is that the values from 1 to 8 do not really mean much. It would
+helpful if we could replace them with something that controls what exactly
+the iscsi tools and kernel modules log.
+
+For example, if we made the debug level argument a bitmap then
+
+iscsiadm -m node --login -d LOGIN_ERRS,PDUS,FUNCTION
+
+might print out extended iscsi login error information (LOGIN_ERRS),
+the iSCSI packets that were sent/receieved (PDUS), and the functions
+that were run (FUNCTION). Note, the use of a bitmapp and the debug
+levels are just an example. Feel free to do something else.
+
+
+We would want to be able to have iscsiadm control the iscsi kernel
+logging as well. There are interfaces like
+/sys/module/libiscsi/paramters/*debug*
+/sys/module/libiscsi_tcp/paramters/*debug*
+/sys/module/iscsi_tcp/paramters/*debug*
+/sys/module/scsi_transport_iscsi/paramters/*debug*
+
+but we would want to extend the debugging options to be finer grained
+and we would want to make it supportable by all iscsi drivers.
+(see #8 on the kernel todo).
+
+---------------------------------------------------------------------------
+
+2. "iscsiadm -m session -P 3" can print out a lot of information about the
+session, but not all configuration values are printed.
+
+iscsiadm should be modified to print out other settings like timeouts,
+Chap settings,  the iSCSI values that were requested vs negotiated for, etc.
+
+---------------------------------------------------------------------------
+
+3. iscsiadm cannot update a setting of a running session. If you want
+to change a timeout you have to run the iscsiadm logout command,
+then update the record value, then login:
+
+iscsiadm -m node -T target -p ip -u
+iscsidm -m node -T target -p ip -o update -n node.session.timeo.replacement_timeout -v 30
+iscsiadm -m node -T target -p ip -l
+
+iscsiadm should be modified to allow updating of a setting without having
+to run the iscsiadm command.
+
+Note that for some settings like iSCSI ones (ImmediateData, FirstBurstLength,
+etc)  that must be negotiated with the target we will have to logout the
+target then re-login, but we should not have to completely destroy the session
+and scsi devices like is done when running the iscsiadm logout command. We
+should be able to pass iscsid the new values and then have iscsid logout and
+relogin.
+
+Other settings like the abort timeout will not need a logout/login. We can
+just pass those to the kernel or iscsid to use.
+
+
+*Being worked on by Tomoaki Nishimura
+
+---------------------------------------------------------------------------
+
+4. iscsiadm will attempt to perform logins/logouts in parallel. Running
+iscsiadm -m node -L, will cause iscsiadm to login to all portals with
+the startup=automatic field set at the same time.
+
+To log into a target, iscsiadm opens a socket to iscsid, sends iscsid a
+request to login to a target, iscsid performs the iSCSI login operation,
+then iscsid sends iscsiadm a reply.
+
+To perform multiple logins iscsiadm will open a socket for each login
+request, then wait for a reply. This is a problem because for 1000s of targets
+we will have 1000s of sockets open. There is a rlimit to control how many
+files a process can have open and iscsiadm currently runs setrlimit to
+increase this.
+
+With users creating lots of virtual iscsi interfaces on the target and
+initiator with each having multiple paths it beomes inefficient to open
+a socket for each requests.
+
+At the very least we want to handle setrlimit RLIMIT_NOFILE limit better,
+and it would be best to just stop openening a socket per login request.
+
+---------------------------------------------------------------------------
+
+5. Make iSCSI log messages humanly readable. In many cases the iscsi tools
+will log a error number value. The most well known is conn error 1011.
+Users should not have to search on google for what this means.
+
+We should:
+
+1. Write a simple table to convert the error values to a string and print
+them out.
+
+2. Document the values, how you commonly hit them and common solutions
+in the iSCSI docs.
+
+
+See session_conn_error and __check_iscsi_status_class as a start.
+
+---------------------------------------------------------------------------
+
+6. Implement broadcast/multicasts support, so the initiator can
+find iSNS servers without the user having to set the iSNS server address.
+
+See
+5.6.5.14. Name Service Heartbeat (Heartbeat)
+in
+http://tools.ietf.org/html//rfc4171
+
+---------------------------------------------------------------------------
+
+7. Open-iscsi uses the open-isns iSNS library. The library might be a little
+too complicated and a little too heavy for what we need. Investigate
+replacing it.
+
+Also explore merging the open-isns and linux-isns projects, so we do not have
+to support multiple isns clients/servers in linux.
+
+---------------------------------------------------------------------------
+
+8. Implement the DHCP iSNS option support, so we the initiator can
+find the iSNS sever without the user having to set the iSNS server address.
+See:
+http://www.ietf.org/rfc/rfc4174.txt
+
+---------------------------------------------------------------------------
+
+9. Some iscsiadm/iscsid operations that access the iscsi DB and sysfs can be
+up to Big O(N^2). Some of the code was written when we thought 64 sessions
+would be a lot and the norm would be 4 or 8. Due to virtualization, cloud use,
+and targets like equallogic that do a target per logical unit (device) we can
+see 1000s of sessions.
+
+- We should look into making the record DB more efficient. Maybe
+time to use a real DB (something small simple and efficient since this
+needs to run in places like the initramfs).
+
+- Rewrite code to look up a running session so we do not have loop
+over every session in sysfs.
+
+
+---------------------------------------------------------------------------
+
+10. Look into using udev's libudev for our sysfs access in iscsiadm/iscsid/
+iscsistart.
+
+---------------------------------------------------------------------------
+
+11. iSCSI lib.
+
+I am working on this one. Hopefully it should be done soon.
+
+---------------------------------------------------------------------------
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/actor.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/actor.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/actor.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/actor.c	2011-08-14 16:48:25.000000000 -0500
@@ -113,14 +113,13 @@ actor_schedule_private(actor_t *thread, 
 		 * state to scheduled, else add current time to ttschedule and
 		 * insert in the queue at the correct point */
 		if (delay_time == 0) {
-			if (poll_in_progress) {
+			/* For head addition, it must go onto the head of the
+			   actor_list regardless if poll is in progress or not
+			 */
+			if (poll_in_progress && !head) {
 				thread->state = ACTOR_POLL_WAITING;
-				if (head)
-					list_add(&thread->list,
-						 &poll_list);
-				else
-					list_add_tail(&thread->list,
-						      &poll_list);
+				list_add_tail(&thread->list,
+					      &poll_list);
 			} else {
 				thread->state = ACTOR_SCHEDULED;
 				if (head)
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/auth.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/auth.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/auth.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/auth.c	2011-08-14 16:48:25.000000000 -0500
@@ -194,27 +194,20 @@ get_random_bytes(unsigned char *data, un
 	fd = open("/dev/urandom", O_RDONLY);
         while (length > 0) {
 
-		if (fd)
-			read(fd, &r, sizeof(long));
-		else
+		if (!fd || read(fd, &r, sizeof(long)) != -1)
 			r = rand();
                 r = r ^ (r >> 8);
                 r = r ^ (r >> 4);
                 n = r & 0x7;
 
-		if (fd)
-			read(fd, &r, sizeof(long));
-		else
+		if (!fd || read(fd, &r, sizeof(long)) != -1)
 			r = rand();
                 r = r ^ (r >> 8);
                 r = r ^ (r >> 5);
                 n = (n << 3) | (r & 0x7);
 
-		if (fd)
-			read(fd, &r, sizeof(long));
-		else
+		if (!fd || read(fd, &r, sizeof(long)) != -1)
 			r = rand();
-
                 r = r ^ (r >> 8);
                 r = r ^ (r >> 5);
                 n = (n << 2) | (r & 0x3);
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/config.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/config.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/config.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/config.h	2011-08-14 16:48:25.000000000 -0500
@@ -141,7 +141,8 @@ struct iscsi_sendtargets_config {
 	int discoveryd_poll_inval;
 	struct iscsi_auth_config auth;
 	struct iscsi_connection_timeout_config conn_timeo;
-	struct iscsi_conn_operational_config iscsi;
+	struct iscsi_conn_operational_config conn_conf;
+	struct iscsi_session_operational_config session_conf;
 };
 
 struct iscsi_isns_config {
@@ -188,21 +189,46 @@ typedef struct session_rec {
 	int					cmds_max;
 	int					queue_depth;
 	int					initial_login_retry_max;
+	int					nr_sessions;
 	struct iscsi_auth_config		auth;
 	struct iscsi_session_timeout_config	timeo;
 	struct iscsi_error_timeout_config	err_timeo;
 	struct iscsi_session_operational_config	iscsi;
+	struct session_info			*info;
+	unsigned                                sid;
+	/*
+	 * This is a flag passed to iscsid.  If set, multiple sessions are
+	 * allowed to be initiated on this record
+	 */
+	unsigned char                           multiple;
 } session_rec_t;
 
 #define ISCSI_TRANSPORT_NAME_MAXLEN 16
+#define ISCSI_MAX_STR_LEN 80
 
 typedef struct iface_rec {
 	struct list_head	list;
 	/* iscsi iface record name */
 	char			name[ISCSI_MAX_IFACE_LEN];
+	uint32_t		iface_num;
 	/* network layer iface name (eth0) */
 	char			netdev[IFNAMSIZ];
 	char			ipaddress[NI_MAXHOST];
+	char			subnet_mask[NI_MAXHOST];
+	char			gateway[NI_MAXHOST];
+	char			bootproto[ISCSI_MAX_STR_LEN];
+	char			ipv6_linklocal[NI_MAXHOST];
+	char			ipv6_router[NI_MAXHOST];
+	char			ipv6_autocfg[NI_MAXHOST];
+	char			linklocal_autocfg[NI_MAXHOST];
+	char			router_autocfg[NI_MAXHOST];
+	uint16_t		vlan_id;
+	uint8_t			vlan_priority;
+	char			vlan_state[ISCSI_MAX_STR_LEN];
+	char			state[ISCSI_MAX_STR_LEN]; /* 0 = disable,
+							   * 1 = enable */
+	uint16_t		mtu;
+	uint16_t		port;
 	/*
 	 * TODO: we may have to make this bigger and interconnect
 	 * specific for infinniband 
@@ -222,6 +248,7 @@ typedef struct node_rec {
 	char			name[TARGET_NAME_MAXLEN];
 	int			tpgt;
 	iscsi_startup_e		startup;
+	int			leading_login;
 	session_rec_t		session;
 	conn_rec_t		conn[ISCSI_CONN_MAX];
 	iface_rec_t		iface;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/cxgb3i.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgb3i.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/cxgb3i.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgb3i.c	1969-12-31 18:00:00.000000000 -0600
@@ -1,24 +0,0 @@
-/*
- * cxgb3i helpers
- *
- * Copyright (C) 2006 Mike Christie
- * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
-#include "initiator.h"
-
-void cxgb3i_create_conn(struct iscsi_conn *conn)
-{
-	/* card can handle up to 15360 bytes */
-	if (conn->max_recv_dlength > 8192)
-		conn->max_recv_dlength = 8192;
-}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/cxgb3i.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgb3i.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/cxgb3i.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgb3i.h	1969-12-31 18:00:00.000000000 -0600
@@ -1,8 +0,0 @@
-#ifndef CXGB3I_TRANSPORT
-#define CXGB3I_TRANSPORT
-
-struct iscsi_conn;
-
-extern void cxgb3i_create_conn(struct iscsi_conn *conn);
-
-#endif
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/cxgbi.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgbi.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/cxgbi.c	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgbi.c	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,24 @@
+/*
+ * cxgb3i/cxgb4i helpers
+ *
+ * Copyright (C) 2006 Mike Christie
+ * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+#include "initiator.h"
+
+void cxgbi_create_conn(struct iscsi_conn *conn)
+{
+	/* card can handle up to 15360 bytes */
+	if (conn->max_recv_dlength > 8192)
+		conn->max_recv_dlength = 8192;
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/cxgbi.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgbi.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/cxgbi.h	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/cxgbi.h	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,8 @@
+#ifndef CXGBI_TRANSPORT
+#define CXGBI_TRANSPORT
+
+struct iscsi_conn;
+
+extern void cxgbi_create_conn(struct iscsi_conn *conn);
+
+#endif
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/dcb_app.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/dcb_app.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/dcb_app.c	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/dcb_app.c	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,387 @@
+/*******************************************************************************
+
+  DCB application support
+  Copyright(c) 2007-2011 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called "COPYING".
+
+  Contact Information:
+  open-lldp Mailing List <lldp-devel@open-lldp.org>
+
+*******************************************************************************/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <asm/errno.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include "dcbnl.h"
+#include "dcb_app.h"
+#include "sysfs.h"
+
+/* Older kernels' rtnetlink.h may not have RTM_[GS]ETDCB */
+#ifndef RTM_GETDCB
+# define RTM_GETDCB 78
+#endif
+#ifndef RTM_SETDCB
+# define RTM_SETDCB 79
+#endif
+
+#define IEEE_SMASK_ETHTYPE	(1 << IEEE_8021QAZ_APP_SEL_ETHERTYPE)
+#define IEEE_SMASK_STREAM	(1 << IEEE_8021QAZ_APP_SEL_STREAM)
+#define IEEE_SMASK_DGRAM	(1 << IEEE_8021QAZ_APP_SEL_DGRAM)
+#define IEEE_SMASK_ANY		(1 << IEEE_8021QAZ_APP_SEL_ANY)
+
+#define NLA_DATA(nla)        ((void *)((char *)(nla) + NLA_HDRLEN))
+#define NLA_NEXT(nla) (struct rtattr *)((char *)nla + NLMSG_ALIGN(nla->rta_len))
+
+/* Maximum size of response requested or message sent */
+#define MAX_MSG_SIZE    1024
+
+static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
+{
+	struct nlmsghdr *nlh;
+	struct dcbmsg *d;
+
+	nlh = malloc(MAX_MSG_SIZE);
+	if (!nlh)
+		return NULL;
+	memset(nlh, 0, MAX_MSG_SIZE);
+	nlh->nlmsg_type = msg_type;
+	nlh->nlmsg_flags = NLM_F_REQUEST;
+	nlh->nlmsg_seq = 0;
+	nlh->nlmsg_pid = getpid();
+	if (msg_type != RTM_GETDCB) {
+		free(nlh);
+		return NULL;
+	}
+
+	nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct dcbmsg));
+	d = NLMSG_DATA(nlh);
+	d->cmd = arg;
+	d->dcb_family = AF_UNSPEC;
+	d->dcb_pad = 0;
+
+	return nlh;
+}
+
+static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
+			      void *attr, __u16 rta_len)
+{
+	struct rtattr *rta;
+
+	rta = (struct rtattr *)((char *)nlh + nlh->nlmsg_len);
+	rta->rta_type = rta_type;
+	rta->rta_len = rta_len + NLA_HDRLEN;
+	if (attr)
+		memcpy(NLA_DATA(rta), attr, rta_len);
+	nlh->nlmsg_len += NLMSG_ALIGN(rta->rta_len);
+
+	return rta;
+}
+
+static int dcbnl_send_msg(int nl_sd, struct nlmsghdr *nlh)
+{
+	struct sockaddr_nl nladdr;
+	void *buf = nlh;
+	int r, len = nlh->nlmsg_len;
+
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+
+	do {
+		r = sendto(nl_sd, buf, len, 0, (struct sockaddr *)&nladdr,
+			sizeof(nladdr));
+	} while (r < 0 && errno == EINTR);
+
+	if (r < 0)
+		return 1;
+
+	return 0;
+}
+
+static struct nlmsghdr *dcbnl_get_msg(int nl_sd)
+{
+	struct nlmsghdr *nlh;
+	int len;
+
+	nlh = malloc(MAX_MSG_SIZE);
+	if (!nlh)
+		return NULL;
+	memset(nlh, 0, MAX_MSG_SIZE);
+
+	len = recv(nl_sd, (void *)nlh, MAX_MSG_SIZE, 0);
+
+	if (len < 0 || nlh->nlmsg_type == NLMSG_ERROR ||
+	    !NLMSG_OK(nlh, (unsigned int)len)) {
+		free(nlh);
+		return NULL;
+	}
+
+	return nlh;
+}
+
+static int get_dcbx_cap(int nl_sd, const char *ifname)
+{
+	struct nlmsghdr *nlh;
+	struct dcbmsg *d;
+	struct rtattr *rta;
+	int rval;
+
+	nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GDCBX);
+	if (!nlh)
+		return -EIO;
+
+	add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+	rval = dcbnl_send_msg(nl_sd, nlh);
+	free(nlh);
+	if (rval)
+		return -EIO;
+
+	/* Receive DCBX capabilities */
+	nlh = dcbnl_get_msg(nl_sd);
+	if (!nlh)
+		return -EIO;
+
+	d = (struct dcbmsg *)NLMSG_DATA(nlh);
+	rta = (struct rtattr *)(((char *)d) +
+			NLMSG_ALIGN(sizeof(struct dcbmsg)));
+
+	if (d->cmd != DCB_CMD_GDCBX || rta->rta_type != DCB_ATTR_DCBX) {
+		free(nlh);
+		return -EIO;
+	}
+
+	rval = *(__u8 *)NLA_DATA(rta);
+	free(nlh);
+	return rval;
+}
+
+static int get_cee_app_pri(int nl_sd, const char *ifname,
+			   __u8 req_idtype, __u16 req_id)
+{
+	struct nlmsghdr *nlh;
+	struct dcbmsg *d;
+	struct rtattr *rta_parent, *rta_child;
+	int rval = 0;
+	__u8 idtype;
+	__u16 id;
+
+	nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GAPP);
+	if (!nlh)
+		return -EIO;
+
+	add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+	rta_parent = add_rta(nlh, DCB_ATTR_APP, NULL, 0);
+
+	rta_child = add_rta(nlh, DCB_APP_ATTR_IDTYPE,
+		(void *)&req_idtype, sizeof(__u8));
+	rta_parent->rta_len += NLA_ALIGN(rta_child->rta_len);
+
+	rta_child = add_rta(nlh, DCB_APP_ATTR_ID,
+		(void *)&req_id, sizeof(__u16));
+	rta_parent->rta_len += NLA_ALIGN(rta_child->rta_len);
+
+	rval = dcbnl_send_msg(nl_sd, nlh);
+	free(nlh);
+	if (rval)
+		return -EIO;
+
+	nlh = dcbnl_get_msg(nl_sd);
+	if (!nlh)
+		return -EIO;
+
+	d = (struct dcbmsg *)NLMSG_DATA(nlh);
+	rta_parent = (struct rtattr *)(((char *)d) +
+		NLMSG_ALIGN(sizeof(struct dcbmsg)));
+
+	if (d->cmd != DCB_CMD_GAPP) {
+		rval = -EIO;
+		goto get_error;
+	}
+	if (rta_parent->rta_type != DCB_ATTR_APP) {
+		rval = -EIO;
+		goto get_error;
+	}
+
+	rta_child = NLA_DATA(rta_parent);
+	rta_parent = NLA_NEXT(rta_parent);
+
+	idtype = *(__u8 *)NLA_DATA(rta_child);
+	rta_child = NLA_NEXT(rta_child);
+	if (idtype != req_idtype) {
+		rval = -EIO;
+		goto get_error;
+	}
+
+	id = *(__u16 *)NLA_DATA(rta_child);
+	rta_child = NLA_NEXT(rta_child);
+	if (id != req_id) {
+		rval = -EIO;
+		goto get_error;
+	}
+
+	rval = *(__u8 *)NLA_DATA(rta_child);
+
+get_error:
+	free(nlh);
+	return rval;
+}
+
+static int
+get_ieee_app_pri(int nl_sd, const char *ifname, __u8 ieee_mask, __u16 req_id)
+{
+	struct nlmsghdr *nlh;
+	struct dcbmsg *d;
+	struct rtattr *rta_parent, *rta_child;
+	int rval;
+
+	nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_IEEE_GET);
+	if (!nlh)
+		return -EIO;
+
+	add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+
+	rval = dcbnl_send_msg(nl_sd, nlh);
+	free(nlh);
+	if (rval)
+		return -EIO;
+
+	nlh = dcbnl_get_msg(nl_sd);
+	if (!nlh)
+		return -EIO;
+
+	d = (struct dcbmsg *)NLMSG_DATA(nlh);
+	rta_parent = (struct rtattr *)(((char *)d) +
+		NLMSG_ALIGN(sizeof(struct dcbmsg)));
+
+	if (d->cmd != DCB_CMD_IEEE_GET) {
+		rval = -EIO;
+		goto get_error;
+	}
+	if (rta_parent->rta_type != DCB_ATTR_IFNAME) {
+		rval = -EIO;
+		goto get_error;
+	}
+
+	rta_parent = NLA_NEXT(rta_parent);
+
+	if (rta_parent->rta_type != DCB_ATTR_IEEE) {
+		rval = -EIO;
+		goto get_error;
+	}
+
+	rta_child = NLA_DATA(rta_parent);
+	rta_parent = NLA_NEXT(rta_parent);
+
+	for (; rta_parent > rta_child; rta_child = NLA_NEXT(rta_child)) {
+		if (rta_child->rta_type == DCB_ATTR_IEEE_APP_TABLE)
+			break;
+	}
+	if (rta_parent <= rta_child) {
+		rval = -EIO;
+		goto get_error;
+	}
+
+	rta_parent = rta_child;
+	rta_child = NLA_DATA(rta_parent);
+	rta_parent = NLA_NEXT(rta_parent);
+
+	rval = 0;
+	for (; rta_parent > rta_child; rta_child = NLA_NEXT(rta_child)) {
+		struct dcb_app *app;
+
+		if (rta_child->rta_type != DCB_ATTR_IEEE_APP)
+			continue;
+		app = (struct dcb_app *)NLA_DATA(rta_child);
+		if (app->protocol != req_id)
+			continue;
+		if ((1 << app->selector) & ieee_mask)
+			rval |= 1 << app->priority;
+	}
+
+get_error:
+	free(nlh);
+	return rval;
+}
+
+static int get_link_ifname(const char *ifname, char *link_ifname)
+{
+	int ifindex;
+
+	if (sysfs_get_int(ifname, "net", "iflink", &ifindex))
+		return -EIO;
+
+	if (!if_indextoname(ifindex, link_ifname))
+		return -ENODEV;
+
+	return 0;
+}
+
+static int get_app_pri(const char *iface, __u8 req_idtype, __u16 req_id,
+		       __u8 ieee_mask)
+{
+	int dcbx_cap;
+	int pri;
+	int nl_sd;
+	char ifname[IFNAMSIZ];
+
+	if (get_link_ifname(iface, ifname))
+		return 0;
+
+	nl_sd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+	if (nl_sd < 0)
+		return -errno;
+
+	dcbx_cap = get_dcbx_cap(nl_sd, ifname);
+	if (dcbx_cap < 0 || !(dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
+		pri = get_cee_app_pri(nl_sd, ifname, req_idtype, req_id);
+	else
+		pri = get_ieee_app_pri(nl_sd, ifname, ieee_mask, req_id);
+
+	close(nl_sd);
+	return pri;
+}
+
+int get_dcb_app_pri_by_stream_port(const char *ifname, int port)
+{
+	return get_app_pri(ifname, DCB_APP_IDTYPE_PORTNUM, port,
+			IEEE_SMASK_STREAM | IEEE_SMASK_ANY);
+}
+
+int get_dcb_app_pri_by_datagram_port(const char *ifname, int port)
+{
+	return get_app_pri(ifname, DCB_APP_IDTYPE_PORTNUM, port,
+			IEEE_SMASK_DGRAM | IEEE_SMASK_ANY);
+}
+
+int get_dcb_app_pri_by_port_sel(const char *ifname, int port, int sel)
+{
+	return get_app_pri(ifname, DCB_APP_IDTYPE_PORTNUM, port,
+			1 << sel);
+}
+
+int get_dcb_app_pri_by_ethtype(const char *ifname, int ethtype)
+{
+	return get_app_pri(ifname, DCB_APP_IDTYPE_ETHTYPE, ethtype,
+			IEEE_SMASK_ETHTYPE);
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/dcb_app.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/dcb_app.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/dcb_app.h	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/dcb_app.h	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,41 @@
+/*******************************************************************************
+
+  DCB application support
+  Copyright(c) 2010-2011 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called "COPYING".
+
+  Contact Information:
+  open-lldp Mailing List <lldp-devel@open-lldp.org>
+
+*******************************************************************************/
+
+#ifndef _DCB_APP_H_
+#define _DCB_APP_H_
+
+int get_dcb_app_pri_by_ethtype(const char *ifname, int ethtype);
+
+int get_dcb_app_pri_by_stream_port(const char *ifname, int port);
+int get_dcb_app_pri_by_datagram_port(const char *ifname, int port);
+
+/*
+ * The selector values for the following call are defined in recent versions
+ * of the dcbnl.h file.
+ */
+int get_dcb_app_pri_by_port_sel(const char *ifname, int port, int sel);
+
+#endif  /* _DCB_APP_H_ */
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/dcbnl.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/dcbnl.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/dcbnl.h	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/dcbnl.h	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,653 @@
+/*
+ * Local copy of the kernel's dcbnl.h
+ *
+ * Copyright (c) 2008-2011, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Author: Lucy Liu <lucy.liu@intel.com>
+ */
+
+#ifndef __LINUX_DCBNL_H__
+#define __LINUX_DCBNL_H__
+
+#include <linux/types.h>
+
+/* IEEE 802.1Qaz std supported values */
+#define IEEE_8021QAZ_MAX_TCS	8
+
+#define IEEE_8021QAZ_TSA_STRICT		0
+#define IEEE_8021QAZ_TSA_CB_SHAPER	1
+#define IEEE_8021QAZ_TSA_ETS		2
+#define IEEE_8021QAZ_TSA_VENDOR		255
+
+/* This structure contains the IEEE 802.1Qaz ETS managed object
+ *
+ * @willing: willing bit in ETS configuration TLV
+ * @ets_cap: indicates supported capacity of ets feature
+ * @cbs: credit based shaper ets algorithm supported
+ * @tc_tx_bw: tc tx bandwidth indexed by traffic class
+ * @tc_rx_bw: tc rx bandwidth indexed by traffic class
+ * @tc_tsa: TSA Assignment table, indexed by traffic class
+ * @prio_tc: priority assignment table mapping 8021Qp to traffic class
+ * @tc_reco_bw: recommended tc bandwidth indexed by traffic class for TLV
+ * @tc_reco_tsa: recommended tc bandwidth indexed by traffic class for TLV
+ * @reco_prio_tc: recommended tc tx bandwidth indexed by traffic class for TLV
+ *
+ * Recommended values are used to set fields in the ETS recommendation TLV
+ * with hardware offloaded LLDP.
+ *
+ * ----
+ *  TSA Assignment 8 bit identifiers
+ *	0	strict priority
+ *	1	credit-based shaper
+ *	2	enhanced transmission selection
+ *	3-254	reserved
+ *	255	vendor specific
+ */
+struct ieee_ets {
+	__u8	willing;
+	__u8	ets_cap;
+	__u8	cbs;
+	__u8	tc_tx_bw[IEEE_8021QAZ_MAX_TCS];
+	__u8	tc_rx_bw[IEEE_8021QAZ_MAX_TCS];
+	__u8	tc_tsa[IEEE_8021QAZ_MAX_TCS];
+	__u8	prio_tc[IEEE_8021QAZ_MAX_TCS];
+	__u8	tc_reco_bw[IEEE_8021QAZ_MAX_TCS];
+	__u8	tc_reco_tsa[IEEE_8021QAZ_MAX_TCS];
+	__u8	reco_prio_tc[IEEE_8021QAZ_MAX_TCS];
+};
+
+/* This structure contains the IEEE 802.1Qaz PFC managed object
+ *
+ * @pfc_cap: Indicates the number of traffic classes on the local device
+ *	     that may simultaneously have PFC enabled.
+ * @pfc_en: bitmap indicating pfc enabled traffic classes
+ * @mbc: enable macsec bypass capability
+ * @delay: the allowance made for a round-trip propagation delay of the
+ *	   link in bits.
+ * @requests: count of the sent pfc frames
+ * @indications: count of the received pfc frames
+ */
+struct ieee_pfc {
+	__u8	pfc_cap;
+	__u8	pfc_en;
+	__u8	mbc;
+	__u16	delay;
+	__u64	requests[IEEE_8021QAZ_MAX_TCS];
+	__u64	indications[IEEE_8021QAZ_MAX_TCS];
+};
+
+/* CEE DCBX std supported values */
+#define CEE_DCBX_MAX_PGS	8
+#define CEE_DCBX_MAX_PRIO	8
+
+/**
+ * struct cee_pg - CEE Priority-Group managed object
+ *
+ * @willing: willing bit in the PG tlv
+ * @error: error bit in the PG tlv
+ * @pg_en: enable bit of the PG feature
+ * @tcs_supported: number of traffic classes supported
+ * @pg_bw: bandwidth percentage for each priority group
+ * @prio_pg: priority to PG mapping indexed by priority
+ */
+struct cee_pg {
+	__u8    willing;
+	__u8    error;
+	__u8    pg_en;
+	__u8    tcs_supported;
+	__u8    pg_bw[CEE_DCBX_MAX_PGS];
+	__u8    prio_pg[CEE_DCBX_MAX_PGS];
+};
+
+/**
+ * struct cee_pfc - CEE PFC managed object
+ *
+ * @willing: willing bit in the PFC tlv
+ * @error: error bit in the PFC tlv
+ * @pfc_en: bitmap indicating pfc enabled traffic classes
+ * @tcs_supported: number of traffic classes supported
+ */
+struct cee_pfc {
+	__u8    willing;
+	__u8    error;
+	__u8    pfc_en;
+	__u8    tcs_supported;
+};
+
+/* IEEE 802.1Qaz std supported values */
+#define IEEE_8021QAZ_APP_SEL_ETHERTYPE	1
+#define IEEE_8021QAZ_APP_SEL_STREAM	2
+#define IEEE_8021QAZ_APP_SEL_DGRAM	3
+#define IEEE_8021QAZ_APP_SEL_ANY	4
+
+/* This structure contains the IEEE 802.1Qaz APP managed object. This
+ * object is also used for the CEE std as well. There is no difference
+ * between the objects.
+ *
+ * @selector: protocol identifier type
+ * @protocol: protocol of type indicated
+ * @priority: 3-bit unsigned integer indicating priority
+ *
+ * ----
+ *  Selector field values
+ *	0	Reserved
+ *	1	Ethertype
+ *	2	Well known port number over TCP or SCTP
+ *	3	Well known port number over UDP or DCCP
+ *	4	Well known port number over TCP, SCTP, UDP, or DCCP
+ *	5-7	Reserved
+ */
+struct dcb_app {
+	__u8	selector;
+	__u8	priority;
+	__u16	protocol;
+};
+
+/**
+ * struct dcb_peer_app_info - APP feature information sent by the peer
+ *
+ * @willing: willing bit in the peer APP tlv
+ * @error: error bit in the peer APP tlv
+ *
+ * In addition to this information the full peer APP tlv also contains
+ * a table of 'app_count' APP objects defined above.
+ */
+struct dcb_peer_app_info {
+	__u8	willing;
+	__u8	error;
+};
+
+struct dcbmsg {
+	__u8               dcb_family;
+	__u8               cmd;
+	__u16              dcb_pad;
+};
+
+/**
+ * enum dcbnl_commands - supported DCB commands
+ *
+ * @DCB_CMD_UNDEFINED: unspecified command to catch errors
+ * @DCB_CMD_GSTATE: request the state of DCB in the device
+ * @DCB_CMD_SSTATE: set the state of DCB in the device
+ * @DCB_CMD_PGTX_GCFG: request the priority group configuration for Tx
+ * @DCB_CMD_PGTX_SCFG: set the priority group configuration for Tx
+ * @DCB_CMD_PGRX_GCFG: request the priority group configuration for Rx
+ * @DCB_CMD_PGRX_SCFG: set the priority group configuration for Rx
+ * @DCB_CMD_PFC_GCFG: request the priority flow control configuration
+ * @DCB_CMD_PFC_SCFG: set the priority flow control configuration
+ * @DCB_CMD_SET_ALL: apply all changes to the underlying device
+ * @DCB_CMD_GPERM_HWADDR: get the permanent MAC address of the underlying
+ *                        device.  Only useful when using bonding.
+ * @DCB_CMD_GCAP: request the DCB capabilities of the device
+ * @DCB_CMD_GNUMTCS: get the number of traffic classes currently supported
+ * @DCB_CMD_SNUMTCS: set the number of traffic classes
+ * @DCB_CMD_GBCN: set backward congestion notification configuration
+ * @DCB_CMD_SBCN: get backward congestion notification configration.
+ * @DCB_CMD_GAPP: get application protocol configuration
+ * @DCB_CMD_SAPP: set application protocol configuration
+ * @DCB_CMD_IEEE_SET: set IEEE 802.1Qaz configuration
+ * @DCB_CMD_IEEE_GET: get IEEE 802.1Qaz configuration
+ * @DCB_CMD_GDCBX: get DCBX engine configuration
+ * @DCB_CMD_SDCBX: set DCBX engine configuration
+ * @DCB_CMD_GFEATCFG: get DCBX features flags
+ * @DCB_CMD_SFEATCFG: set DCBX features negotiation flags
+ * @DCB_CMD_CEE_GET: get CEE aggregated configuration
+ */
+enum dcbnl_commands {
+	DCB_CMD_UNDEFINED,
+
+	DCB_CMD_GSTATE,
+	DCB_CMD_SSTATE,
+
+	DCB_CMD_PGTX_GCFG,
+	DCB_CMD_PGTX_SCFG,
+	DCB_CMD_PGRX_GCFG,
+	DCB_CMD_PGRX_SCFG,
+
+	DCB_CMD_PFC_GCFG,
+	DCB_CMD_PFC_SCFG,
+
+	DCB_CMD_SET_ALL,
+
+	DCB_CMD_GPERM_HWADDR,
+
+	DCB_CMD_GCAP,
+
+	DCB_CMD_GNUMTCS,
+	DCB_CMD_SNUMTCS,
+
+	DCB_CMD_PFC_GSTATE,
+	DCB_CMD_PFC_SSTATE,
+
+	DCB_CMD_BCN_GCFG,
+	DCB_CMD_BCN_SCFG,
+
+	DCB_CMD_GAPP,
+	DCB_CMD_SAPP,
+
+	DCB_CMD_IEEE_SET,
+	DCB_CMD_IEEE_GET,
+
+	DCB_CMD_GDCBX,
+	DCB_CMD_SDCBX,
+
+	DCB_CMD_GFEATCFG,
+	DCB_CMD_SFEATCFG,
+
+	DCB_CMD_CEE_GET,
+
+	__DCB_CMD_ENUM_MAX,
+	DCB_CMD_MAX = __DCB_CMD_ENUM_MAX - 1,
+};
+
+/**
+ * enum dcbnl_attrs - DCB top-level netlink attributes
+ *
+ * @DCB_ATTR_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_ATTR_IFNAME: interface name of the underlying device (NLA_STRING)
+ * @DCB_ATTR_STATE: enable state of DCB in the device (NLA_U8)
+ * @DCB_ATTR_PFC_STATE: enable state of PFC in the device (NLA_U8)
+ * @DCB_ATTR_PFC_CFG: priority flow control configuration (NLA_NESTED)
+ * @DCB_ATTR_NUM_TC: number of traffic classes supported in the device (NLA_U8)
+ * @DCB_ATTR_PG_CFG: priority group configuration (NLA_NESTED)
+ * @DCB_ATTR_SET_ALL: bool to commit changes to hardware or not (NLA_U8)
+ * @DCB_ATTR_PERM_HWADDR: MAC address of the physical device (NLA_NESTED)
+ * @DCB_ATTR_CAP: DCB capabilities of the device (NLA_NESTED)
+ * @DCB_ATTR_NUMTCS: number of traffic classes supported (NLA_NESTED)
+ * @DCB_ATTR_BCN: backward congestion notification configuration (NLA_NESTED)
+ * @DCB_ATTR_IEEE: IEEE 802.1Qaz supported attributes (NLA_NESTED)
+ * @DCB_ATTR_DCBX: DCBX engine configuration in the device (NLA_U8)
+ * @DCB_ATTR_FEATCFG: DCBX features flags (NLA_NESTED)
+ * @DCB_ATTR_CEE: CEE std supported attributes (NLA_NESTED)
+ */
+enum dcbnl_attrs {
+	DCB_ATTR_UNDEFINED,
+
+	DCB_ATTR_IFNAME,
+	DCB_ATTR_STATE,
+	DCB_ATTR_PFC_STATE,
+	DCB_ATTR_PFC_CFG,
+	DCB_ATTR_NUM_TC,
+	DCB_ATTR_PG_CFG,
+	DCB_ATTR_SET_ALL,
+	DCB_ATTR_PERM_HWADDR,
+	DCB_ATTR_CAP,
+	DCB_ATTR_NUMTCS,
+	DCB_ATTR_BCN,
+	DCB_ATTR_APP,
+
+	/* IEEE std attributes */
+	DCB_ATTR_IEEE,
+
+	DCB_ATTR_DCBX,
+	DCB_ATTR_FEATCFG,
+
+	/* CEE nested attributes */
+	DCB_ATTR_CEE,
+
+	__DCB_ATTR_ENUM_MAX,
+	DCB_ATTR_MAX = __DCB_ATTR_ENUM_MAX - 1,
+};
+
+/**
+ * enum ieee_attrs - IEEE 802.1Qaz get/set attributes
+ *
+ * @DCB_ATTR_IEEE_UNSPEC: unspecified
+ * @DCB_ATTR_IEEE_ETS: negotiated ETS configuration
+ * @DCB_ATTR_IEEE_PFC: negotiated PFC configuration
+ * @DCB_ATTR_IEEE_APP_TABLE: negotiated APP configuration
+ * @DCB_ATTR_IEEE_PEER_ETS: peer ETS configuration - get only
+ * @DCB_ATTR_IEEE_PEER_PFC: peer PFC configuration - get only
+ * @DCB_ATTR_IEEE_PEER_APP: peer APP tlv - get only
+ */
+enum ieee_attrs {
+	DCB_ATTR_IEEE_UNSPEC,
+	DCB_ATTR_IEEE_ETS,
+	DCB_ATTR_IEEE_PFC,
+	DCB_ATTR_IEEE_APP_TABLE,
+	DCB_ATTR_IEEE_PEER_ETS,
+	DCB_ATTR_IEEE_PEER_PFC,
+	DCB_ATTR_IEEE_PEER_APP,
+	__DCB_ATTR_IEEE_MAX
+};
+#define DCB_ATTR_IEEE_MAX (__DCB_ATTR_IEEE_MAX - 1)
+
+enum ieee_attrs_app {
+	DCB_ATTR_IEEE_APP_UNSPEC,
+	DCB_ATTR_IEEE_APP,
+	__DCB_ATTR_IEEE_APP_MAX
+};
+#define DCB_ATTR_IEEE_APP_MAX (__DCB_ATTR_IEEE_APP_MAX - 1)
+
+/**
+ * enum cee_attrs - CEE DCBX get attributes
+ *
+ * @DCB_ATTR_CEE_UNSPEC: unspecified
+ * @DCB_ATTR_CEE_PEER_PG: peer PG configuration - get only
+ * @DCB_ATTR_CEE_PEER_PFC: peer PFC configuration - get only
+ * @DCB_ATTR_CEE_PEER_APP: peer APP tlv - get only
+ */
+enum cee_attrs {
+	DCB_ATTR_CEE_UNSPEC,
+	DCB_ATTR_CEE_PEER_PG,
+	DCB_ATTR_CEE_PEER_PFC,
+	DCB_ATTR_CEE_PEER_APP_TABLE,
+	__DCB_ATTR_CEE_MAX
+};
+#define DCB_ATTR_CEE_MAX (__DCB_ATTR_CEE_MAX - 1)
+
+enum peer_app_attr {
+	DCB_ATTR_CEE_PEER_APP_UNSPEC,
+	DCB_ATTR_CEE_PEER_APP_INFO,
+	DCB_ATTR_CEE_PEER_APP,
+	__DCB_ATTR_CEE_PEER_APP_MAX
+};
+#define DCB_ATTR_CEE_PEER_APP_MAX (__DCB_ATTR_CEE_PEER_APP_MAX - 1)
+
+/**
+ * enum dcbnl_pfc_attrs - DCB Priority Flow Control user priority nested attrs
+ *
+ * @DCB_PFC_UP_ATTR_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_PFC_UP_ATTR_0: Priority Flow Control value for User Priority 0 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_1: Priority Flow Control value for User Priority 1 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_2: Priority Flow Control value for User Priority 2 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_3: Priority Flow Control value for User Priority 3 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_4: Priority Flow Control value for User Priority 4 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_5: Priority Flow Control value for User Priority 5 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_6: Priority Flow Control value for User Priority 6 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_7: Priority Flow Control value for User Priority 7 (NLA_U8)
+ * @DCB_PFC_UP_ATTR_MAX: highest attribute number currently defined
+ * @DCB_PFC_UP_ATTR_ALL: apply to all priority flow control attrs (NLA_FLAG)
+ *
+ */
+enum dcbnl_pfc_up_attrs {
+	DCB_PFC_UP_ATTR_UNDEFINED,
+
+	DCB_PFC_UP_ATTR_0,
+	DCB_PFC_UP_ATTR_1,
+	DCB_PFC_UP_ATTR_2,
+	DCB_PFC_UP_ATTR_3,
+	DCB_PFC_UP_ATTR_4,
+	DCB_PFC_UP_ATTR_5,
+	DCB_PFC_UP_ATTR_6,
+	DCB_PFC_UP_ATTR_7,
+	DCB_PFC_UP_ATTR_ALL,
+
+	__DCB_PFC_UP_ATTR_ENUM_MAX,
+	DCB_PFC_UP_ATTR_MAX = __DCB_PFC_UP_ATTR_ENUM_MAX - 1,
+};
+
+/**
+ * enum dcbnl_pg_attrs - DCB Priority Group attributes
+ *
+ * @DCB_PG_ATTR_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_PG_ATTR_TC_0: Priority Group Traffic Class 0 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_1: Priority Group Traffic Class 1 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_2: Priority Group Traffic Class 2 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_3: Priority Group Traffic Class 3 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_4: Priority Group Traffic Class 4 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_5: Priority Group Traffic Class 5 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_6: Priority Group Traffic Class 6 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_7: Priority Group Traffic Class 7 configuration (NLA_NESTED)
+ * @DCB_PG_ATTR_TC_MAX: highest attribute number currently defined
+ * @DCB_PG_ATTR_TC_ALL: apply to all traffic classes (NLA_NESTED)
+ * @DCB_PG_ATTR_BW_ID_0: Percent of link bandwidth for Priority Group 0 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_1: Percent of link bandwidth for Priority Group 1 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_2: Percent of link bandwidth for Priority Group 2 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_3: Percent of link bandwidth for Priority Group 3 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_4: Percent of link bandwidth for Priority Group 4 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_5: Percent of link bandwidth for Priority Group 5 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_6: Percent of link bandwidth for Priority Group 6 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_7: Percent of link bandwidth for Priority Group 7 (NLA_U8)
+ * @DCB_PG_ATTR_BW_ID_MAX: highest attribute number currently defined
+ * @DCB_PG_ATTR_BW_ID_ALL: apply to all priority groups (NLA_FLAG)
+ *
+ */
+enum dcbnl_pg_attrs {
+	DCB_PG_ATTR_UNDEFINED,
+
+	DCB_PG_ATTR_TC_0,
+	DCB_PG_ATTR_TC_1,
+	DCB_PG_ATTR_TC_2,
+	DCB_PG_ATTR_TC_3,
+	DCB_PG_ATTR_TC_4,
+	DCB_PG_ATTR_TC_5,
+	DCB_PG_ATTR_TC_6,
+	DCB_PG_ATTR_TC_7,
+	DCB_PG_ATTR_TC_MAX,
+	DCB_PG_ATTR_TC_ALL,
+
+	DCB_PG_ATTR_BW_ID_0,
+	DCB_PG_ATTR_BW_ID_1,
+	DCB_PG_ATTR_BW_ID_2,
+	DCB_PG_ATTR_BW_ID_3,
+	DCB_PG_ATTR_BW_ID_4,
+	DCB_PG_ATTR_BW_ID_5,
+	DCB_PG_ATTR_BW_ID_6,
+	DCB_PG_ATTR_BW_ID_7,
+	DCB_PG_ATTR_BW_ID_MAX,
+	DCB_PG_ATTR_BW_ID_ALL,
+
+	__DCB_PG_ATTR_ENUM_MAX,
+	DCB_PG_ATTR_MAX = __DCB_PG_ATTR_ENUM_MAX - 1,
+};
+
+/**
+ * enum dcbnl_tc_attrs - DCB Traffic Class attributes
+ *
+ * @DCB_TC_ATTR_PARAM_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_TC_ATTR_PARAM_PGID: (NLA_U8) Priority group the traffic class belongs to
+ *                          Valid values are:  0-7
+ * @DCB_TC_ATTR_PARAM_UP_MAPPING: (NLA_U8) Traffic class to user priority map
+ *                                Some devices may not support changing the
+ *                                user priority map of a TC.
+ * @DCB_TC_ATTR_PARAM_STRICT_PRIO: (NLA_U8) Strict priority setting
+ *                                 0 - none
+ *                                 1 - group strict
+ *                                 2 - link strict
+ * @DCB_TC_ATTR_PARAM_BW_PCT: optional - (NLA_U8) If supported by the device and
+ *                            not configured to use link strict priority,
+ *                            this is the percentage of bandwidth of the
+ *                            priority group this traffic class belongs to
+ * @DCB_TC_ATTR_PARAM_ALL: (NLA_FLAG) all traffic class parameters
+ *
+ */
+enum dcbnl_tc_attrs {
+	DCB_TC_ATTR_PARAM_UNDEFINED,
+
+	DCB_TC_ATTR_PARAM_PGID,
+	DCB_TC_ATTR_PARAM_UP_MAPPING,
+	DCB_TC_ATTR_PARAM_STRICT_PRIO,
+	DCB_TC_ATTR_PARAM_BW_PCT,
+	DCB_TC_ATTR_PARAM_ALL,
+
+	__DCB_TC_ATTR_PARAM_ENUM_MAX,
+	DCB_TC_ATTR_PARAM_MAX = __DCB_TC_ATTR_PARAM_ENUM_MAX - 1,
+};
+
+/**
+ * enum dcbnl_cap_attrs - DCB Capability attributes
+ *
+ * @DCB_CAP_ATTR_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_CAP_ATTR_ALL: (NLA_FLAG) all capability parameters
+ * @DCB_CAP_ATTR_PG: (NLA_U8) device supports Priority Groups
+ * @DCB_CAP_ATTR_PFC: (NLA_U8) device supports Priority Flow Control
+ * @DCB_CAP_ATTR_UP2TC: (NLA_U8) device supports user priority to
+ *                               traffic class mapping
+ * @DCB_CAP_ATTR_PG_TCS: (NLA_U8) bitmap where each bit represents a
+ *                                number of traffic classes the device
+ *                                can be configured to use for Priority Groups
+ * @DCB_CAP_ATTR_PFC_TCS: (NLA_U8) bitmap where each bit represents a
+ *                                 number of traffic classes the device can be
+ *                                 configured to use for Priority Flow Control
+ * @DCB_CAP_ATTR_GSP: (NLA_U8) device supports group strict priority
+ * @DCB_CAP_ATTR_BCN: (NLA_U8) device supports Backwards Congestion
+ *                             Notification
+ * @DCB_CAP_ATTR_DCBX: (NLA_U8) device supports DCBX engine
+ *
+ */
+enum dcbnl_cap_attrs {
+	DCB_CAP_ATTR_UNDEFINED,
+	DCB_CAP_ATTR_ALL,
+	DCB_CAP_ATTR_PG,
+	DCB_CAP_ATTR_PFC,
+	DCB_CAP_ATTR_UP2TC,
+	DCB_CAP_ATTR_PG_TCS,
+	DCB_CAP_ATTR_PFC_TCS,
+	DCB_CAP_ATTR_GSP,
+	DCB_CAP_ATTR_BCN,
+	DCB_CAP_ATTR_DCBX,
+
+	__DCB_CAP_ATTR_ENUM_MAX,
+	DCB_CAP_ATTR_MAX = __DCB_CAP_ATTR_ENUM_MAX - 1,
+};
+
+/**
+ * DCBX capability flags
+ *
+ * @DCB_CAP_DCBX_HOST: DCBX negotiation is performed by the host LLDP agent.
+ *                     'set' routines are used to configure the device with
+ *                     the negotiated parameters
+ *
+ * @DCB_CAP_DCBX_LLD_MANAGED: DCBX negotiation is not performed in the host but
+ *                            by another entity
+ *                            'get' routines are used to retrieve the
+ *                            negotiated parameters
+ *                            'set' routines can be used to set the initial
+ *                            negotiation configuration
+ *
+ * @DCB_CAP_DCBX_VER_CEE: for a non-host DCBX engine, indicates the engine
+ *                        supports the CEE protocol flavor
+ *
+ * @DCB_CAP_DCBX_VER_IEEE: for a non-host DCBX engine, indicates the engine
+ *                         supports the IEEE protocol flavor
+ *
+ * @DCB_CAP_DCBX_STATIC: for a non-host DCBX engine, indicates the engine
+ *                       supports static configuration (i.e no actual
+ *                       negotiation is performed negotiated parameters equal
+ *                       the initial configuration)
+ *
+ */
+#define DCB_CAP_DCBX_HOST		0x01
+#define DCB_CAP_DCBX_LLD_MANAGED	0x02
+#define DCB_CAP_DCBX_VER_CEE		0x04
+#define DCB_CAP_DCBX_VER_IEEE		0x08
+#define DCB_CAP_DCBX_STATIC		0x10
+
+/**
+ * enum dcbnl_numtcs_attrs - number of traffic classes
+ *
+ * @DCB_NUMTCS_ATTR_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_NUMTCS_ATTR_ALL: (NLA_FLAG) all traffic class attributes
+ * @DCB_NUMTCS_ATTR_PG: (NLA_U8) number of traffic classes used for
+ *                               priority groups
+ * @DCB_NUMTCS_ATTR_PFC: (NLA_U8) number of traffic classes which can
+ *                                support priority flow control
+ */
+enum dcbnl_numtcs_attrs {
+	DCB_NUMTCS_ATTR_UNDEFINED,
+	DCB_NUMTCS_ATTR_ALL,
+	DCB_NUMTCS_ATTR_PG,
+	DCB_NUMTCS_ATTR_PFC,
+
+	__DCB_NUMTCS_ATTR_ENUM_MAX,
+	DCB_NUMTCS_ATTR_MAX = __DCB_NUMTCS_ATTR_ENUM_MAX - 1,
+};
+
+enum dcbnl_bcn_attrs{
+	DCB_BCN_ATTR_UNDEFINED = 0,
+
+	DCB_BCN_ATTR_RP_0,
+	DCB_BCN_ATTR_RP_1,
+	DCB_BCN_ATTR_RP_2,
+	DCB_BCN_ATTR_RP_3,
+	DCB_BCN_ATTR_RP_4,
+	DCB_BCN_ATTR_RP_5,
+	DCB_BCN_ATTR_RP_6,
+	DCB_BCN_ATTR_RP_7,
+	DCB_BCN_ATTR_RP_ALL,
+
+	DCB_BCN_ATTR_BCNA_0,
+	DCB_BCN_ATTR_BCNA_1,
+	DCB_BCN_ATTR_ALPHA,
+	DCB_BCN_ATTR_BETA,
+	DCB_BCN_ATTR_GD,
+	DCB_BCN_ATTR_GI,
+	DCB_BCN_ATTR_TMAX,
+	DCB_BCN_ATTR_TD,
+	DCB_BCN_ATTR_RMIN,
+	DCB_BCN_ATTR_W,
+	DCB_BCN_ATTR_RD,
+	DCB_BCN_ATTR_RU,
+	DCB_BCN_ATTR_WRTT,
+	DCB_BCN_ATTR_RI,
+	DCB_BCN_ATTR_C,
+	DCB_BCN_ATTR_ALL,
+
+	__DCB_BCN_ATTR_ENUM_MAX,
+	DCB_BCN_ATTR_MAX = __DCB_BCN_ATTR_ENUM_MAX - 1,
+};
+
+/**
+ * enum dcb_general_attr_values - general DCB attribute values
+ *
+ * @DCB_ATTR_UNDEFINED: value used to indicate an attribute is not supported
+ *
+ */
+enum dcb_general_attr_values {
+	DCB_ATTR_VALUE_UNDEFINED = 0xff
+};
+
+#define DCB_APP_IDTYPE_ETHTYPE	0x00
+#define DCB_APP_IDTYPE_PORTNUM	0x01
+enum dcbnl_app_attrs {
+	DCB_APP_ATTR_UNDEFINED,
+
+	DCB_APP_ATTR_IDTYPE,
+	DCB_APP_ATTR_ID,
+	DCB_APP_ATTR_PRIORITY,
+
+	__DCB_APP_ATTR_ENUM_MAX,
+	DCB_APP_ATTR_MAX = __DCB_APP_ATTR_ENUM_MAX - 1,
+};
+
+/**
+ * enum dcbnl_featcfg_attrs - features conifiguration flags
+ *
+ * @DCB_FEATCFG_ATTR_UNDEFINED: unspecified attribute to catch errors
+ * @DCB_FEATCFG_ATTR_ALL: (NLA_FLAG) all features configuration attributes
+ * @DCB_FEATCFG_ATTR_PG: (NLA_U8) configuration flags for priority groups
+ * @DCB_FEATCFG_ATTR_PFC: (NLA_U8) configuration flags for priority
+ *                                 flow control
+ * @DCB_FEATCFG_ATTR_APP: (NLA_U8) configuration flags for application TLV
+ *
+ */
+#define DCB_FEATCFG_ERROR	0x01	/* error in feature resolution */
+#define DCB_FEATCFG_ENABLE	0x02	/* enable feature */
+#define DCB_FEATCFG_WILLING	0x04	/* feature is willing */
+#define DCB_FEATCFG_ADVERTISE	0x08	/* advertise feature */
+enum dcbnl_featcfg_attrs {
+	DCB_FEATCFG_ATTR_UNDEFINED,
+	DCB_FEATCFG_ATTR_ALL,
+	DCB_FEATCFG_ATTR_PG,
+	DCB_FEATCFG_ATTR_PFC,
+	DCB_FEATCFG_ATTR_APP,
+
+	__DCB_FEATCFG_ATTR_ENUM_MAX,
+	DCB_FEATCFG_ATTR_MAX = __DCB_FEATCFG_ATTR_ENUM_MAX - 1,
+};
+
+#endif /* __LINUX_DCBNL_H__ */
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/discovery.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/discovery.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/discovery.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/discovery.c	2011-08-14 16:48:25.000000000 -0500
@@ -43,6 +43,12 @@
 #include "fw_context.h"
 #include "iscsid_req.h"
 #include "iscsi_util.h"
+#include "transport.h"
+#include "iscsi_sysfs.h"
+#include "iscsi_ipc.h"
+#include "iface.h"
+#include "iscsi_timer.h"
+#include "iscsi_err.h"
 /* libisns includes */
 #include "isns.h"
 #include "paths.h"
@@ -54,10 +60,9 @@
 
 #define DISCOVERY_NEED_RECONNECT 0xdead0001
 
-static int rediscover = 0;
-
 static char initiator_name[TARGET_NAME_MAXLEN + 1];
 static char initiator_alias[TARGET_NAME_MAXLEN + 1];
+static struct iscsi_ev_context ipc_ev_context;
 
 static int request_initiator_name(void)
 {
@@ -75,7 +80,7 @@ static int request_initiator_name(void)
 
 	rc = iscsid_exec_req(&req, &rsp, 1);
 	if (rc)
-		return EIO;
+		return rc;
 
 	if (rsp.u.config.var[0] != '\0')
 		strcpy(initiator_name, rsp.u.config.var);
@@ -107,14 +112,14 @@ int discovery_isns_set_servername(char *
 
 	if (port > USHRT_MAX) {
 		log_error("Invalid port %d\n", port);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	/* 5 for port and 1 for colon and 1 for null */
 	len = strlen(address) + 7;
 	server = calloc(1, len);
 	if (!server)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	snprintf(server, len, "%s:%d", address, port);
 	isns_assign_string(&isns_config.ic_server_name, server);
@@ -136,11 +141,11 @@ int discovery_isns_query(struct discover
 	isns_config.ic_security = 0;
 	source = isns_source_create_iscsi(iname);
 	if (!source)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	clnt = isns_create_client(NULL, iname); 
 	if (!clnt) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_src;
 	}
 
@@ -158,7 +163,7 @@ int discovery_isns_query(struct discover
 
 	qry = isns_create_query2(clnt, &key_attrs, source);
 	if (!qry) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_clnt;
 	}
 
@@ -177,11 +182,11 @@ int discovery_isns_query(struct discover
 		break;
 	case ISNS_SOURCE_UNKNOWN:
 		/* server requires that we are registered but we are not */
-		rc = ENOENT;
+		rc = ISCSI_ERR_ISNS_REG_FAILED;
 		goto free_query;
 	default:
 		log_error("iSNS discovery failed: %s", isns_strerror(status));
-		rc = EIO;
+		rc = ISCSI_ERR_ISNS_QUERY;
 		goto free_query;
 	}
 
@@ -189,7 +194,7 @@ int discovery_isns_query(struct discover
 	if (status) {
 		log_error("Unable to extract object list from query "
 			  "response: %s\n", isns_strerror(status));
-		rc = EIO;
+		rc = ISCSI_ERR;
 		goto free_query;
 	}
 
@@ -239,7 +244,7 @@ int discovery_isns_query(struct discover
 
 		rec = calloc(1, sizeof(*rec));
 		if (!rec) {
-			rc = ENOMEM;
+			rc = ISCSI_ERR_NOMEM;
 			goto destroy_list;
 		}
 
@@ -291,11 +296,11 @@ static int discovery_isns_reg_node(const
 
 	source = isns_source_create_iscsi(iname);
 	if (!source)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	clnt = isns_create_client(NULL, iname); 
 	if (!clnt) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_src;
 	}
 
@@ -303,7 +308,7 @@ static int discovery_isns_reg_node(const
 				 ISNS_DEVICE_DEREGISTER,
 				 source, NULL);
 	if (!reg) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_clnt;
 	}
 
@@ -318,7 +323,7 @@ static int discovery_isns_reg_node(const
 		log_error("Could not %s %s with iSNS server: %s.",
 			  reg ? "register" : "deregister", iname,
 			  isns_strerror(status));
-		rc = EIO;
+		rc = ISCSI_ERR_ISNS_REG_FAILED;
 	} else
 		log_debug(1, "%s %s with iSNS server successful.",
 			  op_reg ? "register" : "deregister", iname);
@@ -339,11 +344,17 @@ int discovery_isns(void *data, struct if
 	if (iface && strlen(iface->iname))
 		iname = iface->iname;
 	else {
-		if (request_initiator_name() || initiator_name[0] == '\0') {
+		rc = request_initiator_name();
+		if (rc) {
 			log_error("Cannot perform discovery. Initiatorname "
 				  "required.");
-			return EINVAL;
+			return rc;
+		} else if (initiator_name[0] == '\0') {
+			log_error("Cannot perform discovery. Invalid "
+				  "Initiatorname.");
+			return ISCSI_ERR_INVAL;
 		}
+
 		iname = initiator_name;
 	}
 
@@ -352,7 +363,7 @@ int discovery_isns(void *data, struct if
 		return rc;
 retry:
 	rc = discovery_isns_query(drec, iname, NULL, rec_list);
-	if (!registered && rc == ENOENT) {
+	if (!registered && rc == ISCSI_ERR_ISNS_REG_FAILED) {
 		rc = discovery_isns_reg_node(iname, 1);
 		if (!rc) {
 			registered = 1;
@@ -396,7 +407,7 @@ int discovery_fw(void *data, struct ifac
 		if (!rec) {
 			log_error("Could not convert firmware info to "
 				  "node record.\n");
-			rc = ENOMEM;
+			rc = ISCSI_ERR_NOMEM;
 			goto free_targets;
 		}
 		rec->disc_type = drec->type;
@@ -428,10 +439,10 @@ int discovery_offload_sendtargets(int ho
 
 	/* resolve the DiscoveryAddress to an IP address */
 	sprintf(default_port, "%d", drec->port);
-	if (resolve_address(drec->address, default_port, &ss)) {
-		log_error("Cannot resolve host name %s.", drec->address);
-		return EIO;
-	}       
+	rc = resolve_address(drec->address, default_port, &ss);
+	if (rc)
+		return rc;
+
 	req.u.st.ss = ss;
 
 	/*
@@ -447,8 +458,8 @@ int discovery_offload_sendtargets(int ho
 	if (rc) {
 		log_error("Could not offload sendtargets to %s.\n",
 			  drec->address);
-		iscsid_handle_error(rc);
-		return EIO;
+		iscsi_err_print_msg(rc);
+		return rc;
 	}
 
 	return 0;
@@ -490,15 +501,12 @@ request_targets(iscsi_session_t *session
 
 	if (!iscsi_add_text(hdr, data, sizeof (data), "SendTargets", "All")) {
 		log_error("failed to add SendTargets text key");
-		exit(1);
+		return 0;
 	}
 
 	text.ttt = ISCSI_RESERVED_TAG;
 	text.flags = ISCSI_FLAG_CMD_FINAL;
 
-	if (++session->itt == ISCSI_RESERVED_TAG)
-		session->itt = 1;
-
 	if (!iscsi_io_send_pdu(&session->conn[0], hdr, ISCSI_DIGEST_NONE, data,
 		    ISCSI_DIGEST_NONE, session->conn[0].active_timeout)) {
 		log_error("failed to send SendTargets PDU");
@@ -527,9 +535,6 @@ iterate_targets(iscsi_session_t *session
 	text.ttt = ttt;
 	text.flags = ISCSI_FLAG_CMD_FINAL;
 
-	if (++session->itt == ISCSI_RESERVED_TAG)
-		session->itt = 1;
-
 	if (!iscsi_io_send_pdu(&session->conn[0], pdu, ISCSI_DIGEST_NONE, data,
 		    ISCSI_DIGEST_NONE, session->conn[0].active_timeout)) {
 		log_error("failed to send empty text PDU");
@@ -543,19 +548,13 @@ static int add_portal(struct list_head *
 		      char *targetname, char *address, char *port, char *tag)
 {
 	struct sockaddr_storage ss;
-	char host[NI_MAXHOST];
 	struct node_rec *rec;
 
-	/* resolve the address, in case it was a DNS name */
 	if (resolve_address(address, port, &ss)) {
 		log_error("cannot resolve %s", address);
 		return 0;
 	}
 
-	/* convert the resolved name to text */
-	getnameinfo((struct sockaddr *) &ss, sizeof(ss),
-		    host, sizeof(host), NULL, 0, NI_NUMERICHOST);
-
 	rec = calloc(1, sizeof(*rec));
 	if (!rec)
 		return 0;
@@ -582,7 +581,7 @@ static int add_portal(struct list_head *
 
 static int
 add_target_record(char *name, char *end, discovery_rec_t *drec,
-		  struct list_head *rec_list, char *default_port)
+		  struct list_head *rec_list)
 {
 	char *text = NULL;
 	char *nul = name;
@@ -625,11 +624,16 @@ add_target_record(char *name, char *end,
 			log_error("no default address known for target %s",
 				  name);
 			return 0;
-		} else if (!add_portal(rec_list, drec, name, drec->address,
-				       default_port, NULL)) {
-			log_error("failed to add default portal, ignoring "
-				  "target %s", name);
-			return 0;
+		} else {
+			char default_port[NI_MAXSERV];
+
+			sprintf(default_port, "%d", drec->port);
+			if (!add_portal(rec_list, drec, name, drec->address,
+				        default_port, NULL)) {
+				log_error("failed to add default portal, "
+					  "ignoring target %s", name);
+				return 0;
+			}
 		}
 		/* finished adding the default */
 		return 1;
@@ -681,8 +685,7 @@ add_target_record(char *name, char *end,
 static int
 process_sendtargets_response(struct str_buffer *sendtargets,
 			     int final, discovery_rec_t *drec,
-			     struct list_head *rec_list,
-			     char *default_port)
+			     struct list_head *rec_list)
 {
 	char *start = str_buffer_data(sendtargets);
 	char *text = start;
@@ -733,8 +736,7 @@ process_sendtargets_response(struct str_
 				 * "TargetName=" prefix.
 				 */
 				if (!add_target_record(record + 11, text,
-							drec, rec_list,
-							default_port)) {
+							drec, rec_list)) {
 					log_error(
 					       "failed to add target record");
 					str_truncate_buffer(sendtargets, 0);
@@ -762,7 +764,7 @@ process_sendtargets_response(struct str_
 				 "line %s",
 				 record, record);
 			if (add_target_record (record + 11, text,
-					       drec, rec_list, default_port)) {
+					       drec, rec_list)) {
 				num_targets++;
 				record = NULL;
 				str_truncate_buffer(sendtargets, 0);
@@ -792,110 +794,47 @@ process_sendtargets_response(struct str_
 	return 1;
 }
 
-static void
-clear_timer(struct timeval *timer)
-{
-	memset(timer, 0, sizeof (*timer));
-}
-
-/* set timer to now + seconds */
-static void
-set_timer(struct timeval *timer, int seconds)
-{
-	if (timer) {
-		memset(timer, 0, sizeof (*timer));
-		gettimeofday(timer, NULL);
-
-		timer->tv_sec += seconds;
-	}
-}
-
-static int
-timer_expired(struct timeval *timer)
-{
-	struct timeval now;
-
-	/* no timer, can't have expired */
-	if ((timer == NULL) || ((timer->tv_sec == 0) && (timer->tv_usec == 0)))
-		return 0;
-
-	memset(&now, 0, sizeof (now));
-	gettimeofday(&now, NULL);
-
-	if (now.tv_sec > timer->tv_sec)
-		return 1;
-	if ((now.tv_sec == timer->tv_sec) && (now.tv_usec >= timer->tv_usec))
-		return 1;
-	return 0;
-}
-
-static int
-msecs_until(struct timeval *timer)
+static void iscsi_free_session(struct iscsi_session *session)
 {
-	struct timeval now;
-	int msecs;
-	long partial;
-
-	/* no timer, can't have expired, infinite time til it expires */
-	if ((timer == NULL) || ((timer->tv_sec == 0) && (timer->tv_usec == 0)))
-		return -1;
-
-	memset(&now, 0, sizeof (now));
-	gettimeofday(&now, NULL);
-
-	/* already expired? */
-	if (now.tv_sec > timer->tv_sec)
-		return 0;
-	if ((now.tv_sec == timer->tv_sec) && (now.tv_usec >= timer->tv_usec))
-		return 0;
-
-	/* not expired yet, do the math */
-	partial = timer->tv_usec - now.tv_usec;
-	if (partial < 0) {
-		partial += 1000 * 1000;
-		msecs = (partial + 500) / 1000;
-		msecs += (timer->tv_sec - now.tv_sec - 1) * 1000;
-	} else {
-		msecs = (partial + 500) / 1000;
-		msecs += (timer->tv_sec - now.tv_sec) * 1000;
-	}
-
-	return msecs;
+	list_del_init(&session->list);
+	free(session);
 }
 
 static iscsi_session_t *
-init_new_session(struct iscsi_sendtargets_config *config,
-		 struct iface_rec *iface)
+iscsi_alloc_session(struct iscsi_sendtargets_config *config,
+		    struct iface_rec *iface, int *rc)
 {
 	iscsi_session_t *session;
 
+	*rc = 0;
+
 	session = calloc(1, sizeof (*session));
-	if (session == NULL)
-		goto done;
+	if (session == NULL) {
+		*rc = ISCSI_ERR_NOMEM;
+		return NULL;
+	}
 
+	session->t = iscsi_sysfs_get_transport_by_name(iface->transport_name);
+	if (!session->t) {
+		log_error("iSCSI driver %s is not loaded. Load the module "
+			  "then retry the command.\n", iface->transport_name);
+		*rc = ISCSI_ERR_TRANS_NOT_FOUND;
+		goto fail;
+	}
+
+	INIT_LIST_HEAD(&session->list);
 	/* initialize the session's leading connection */
+	session->conn[0].id = 0;
 	session->conn[0].socket_fd = -1;
+	session->conn[0].session = session;
 	session->conn[0].login_timeout = config->conn_timeo.login_timeout;
 	session->conn[0].auth_timeout = config->conn_timeo.auth_timeout;
 	session->conn[0].active_timeout = config->conn_timeo.active_timeout;
-	session->conn[0].hdrdgst_en = ISCSI_DIGEST_NONE;
-	session->conn[0].datadgst_en = ISCSI_DIGEST_NONE;
-
-	session->conn[0].max_recv_dlength =
-					config->iscsi.MaxRecvDataSegmentLength;
-	if (session->conn[0].max_recv_dlength < ISCSI_MIN_MAX_RECV_SEG_LEN ||
-	    session->conn[0].max_recv_dlength > ISCSI_MAX_MAX_RECV_SEG_LEN) {
-		log_error("Invalid iscsi.MaxRecvDataSegmentLength. Must be "
-			  "within %u and %u. Setting to %u.",
-			  ISCSI_MIN_MAX_RECV_SEG_LEN,
-			  ISCSI_MAX_MAX_RECV_SEG_LEN,
-			  DEF_INI_DISC_MAX_RECV_SEG_LEN);
-		session->conn[0].max_recv_dlength =
-						DEF_INI_DISC_MAX_RECV_SEG_LEN;
-	}
-	session->conn[0].max_xmit_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN;
-
+	session->conn[0].noop_out_timeout = 0;
+	session->conn[0].noop_out_interval = 0;
 	session->reopen_cnt = config->reopen_max + 1;
+	iscsi_copy_operational_params(&session->conn[0], &config->session_conf,
+				      &config->conn_conf);
 
 	/* OUI and uniqifying number */
 	session->isid[0] = DRIVER_ISID_0;
@@ -905,111 +844,41 @@ init_new_session(struct iscsi_sendtarget
 	session->isid[4] = 0;
 	session->isid[5] = 0;
 
-	request_initiator_name();
-
 	if (iface && strlen(iface->iname)) {
 		strcpy(initiator_name, iface->iname);
 		/* MNC TODO add iface alias */
 	} else {
-		if (initiator_name[0] == '\0') {
+		*rc = request_initiator_name();
+		if (*rc) {
 			log_error("Cannot perform discovery. Initiatorname "
 				  "required.");
-			free(session);
-			return NULL;
+			goto fail;
+		} else if (initiator_name[0] == '\0') {
+			log_error("Cannot perform discovery. Invalid "
+				  "Initiatorname.");
+			*rc = ISCSI_ERR_INVAL;
+			goto fail;
 		}
 	}
 
+	iface_copy(&session->nrec.iface, iface);
 	session->initiator_name = initiator_name;
 	session->initiator_alias = initiator_alias;
 	session->portal_group_tag = PORTAL_GROUP_TAG_UNKNOWN;
 	session->type = ISCSI_SESSION_TYPE_DISCOVERY;
-done:
-	return session;
-}
-
+	session->id = -1;
 
-static int
-setup_authentication(iscsi_session_t *session,
-		     discovery_rec_t *drec,
-		     struct iscsi_sendtargets_config *config)
-{
-	int rc;
-
-	rc = 1;
-
-	/* if we have any incoming credentials, we insist on authenticating
-	 * the target or not logging in at all
-	 */
-	if (config->auth.username_in[0]
-	    || config->auth.password_in_length) {
-		session->bidirectional_auth = 1;
-
-		/* sanity check the config */
-		if (config->auth.password_length == 0) {
-			log_error(
-			       "discovery process to %s:%d has incoming "
-			       "authentication credentials but has no outgoing "
-			       "credentials configured",
-			       drec->address, drec->port);
-			log_error(
-			       "discovery process to %s:%d exiting, bad "
-			       "configuration",
-			       drec->address, drec->port);
-			rc = 0;
-			goto done;
-		}
-	} else {
-		/* no or 1-way authentication */
-		session->bidirectional_auth = 0;
-	}
+	/* setup authentication variables for the session*/
+	*rc = iscsi_setup_authentication(session, &config->auth);
+	if (*rc)
+		goto fail;
 
-	/* copy in whatever credentials we have */
-	strlcpy(session->username, config->auth.username,
-		sizeof (session->username));
-	session->username[sizeof (session->username) - 1] = '\0';
-	if ((session->password_length = config->auth.password_length))
-		memcpy(session->password, config->auth.password,
-		       session->password_length);
-
-	strlcpy(session->username_in, config->auth.username_in,
-		sizeof (session->username_in));
-	session->username_in[sizeof (session->username_in) - 1] = '\0';
-	if ((session->password_in_length =
-	     config->auth.password_in_length))
-		memcpy(session->password_in, config->auth.password_in,
-		       session->password_in_length);
-
-	if (session->password_length || session->password_in_length) {
-		/* setup the auth buffers */
-		session->auth_buffers[0].address = &session->auth_client_block;
-		session->auth_buffers[0].length =
-		    sizeof (session->auth_client_block);
-		session->auth_buffers[1].address =
-		    &session->auth_recv_string_block;
-		session->auth_buffers[1].length =
-		    sizeof (session->auth_recv_string_block);
-
-		session->auth_buffers[2].address =
-		    &session->auth_send_string_block;
-		session->auth_buffers[2].length =
-		    sizeof (session->auth_send_string_block);
-
-		session->auth_buffers[3].address =
-		    &session->auth_recv_binary_block;
-		session->auth_buffers[3].length =
-		    sizeof (session->auth_recv_binary_block);
-
-		session->auth_buffers[4].address =
-		    &session->auth_send_binary_block;
-		session->auth_buffers[4].length =
-		    sizeof (session->auth_send_binary_block);
+	list_add_tail(&session->list, &session->t->sessions);
+	return session;
 
-		session->num_auth_buffers = 5;
-	} else {
-		session->num_auth_buffers = 0;
-	}
- done:
-	return(rc);
+fail:
+	free(session);
+	return NULL;
 }
 
 static int
@@ -1018,7 +887,6 @@ process_recvd_pdu(struct iscsi_hdr *pdu,
 		  struct list_head *rec_list,
 		  iscsi_session_t *session,
 		  struct str_buffer *sendtargets,
-		  char *default_port,
 		  int *active,
 		  int *valid_text,
 		  char *data)
@@ -1063,8 +931,7 @@ process_recvd_pdu(struct iscsi_hdr *pdu,
 			process_sendtargets_response(sendtargets,
 						     final,
 						     drec,
-						     rec_list,
-						     default_port);
+						     rec_list);
 
 			if (final) {
 				/* SendTargets exchange is now complete
@@ -1095,12 +962,11 @@ process_recvd_pdu(struct iscsi_hdr *pdu,
 	return(rc);
 }
 
+#if 0 /* Unused */
 /*
- * Make a best effort to logout the session, then disconnect the
- * socket.
+ * Make a best effort to logout the session.
  */
-static void
-iscsi_logout_and_disconnect(iscsi_session_t * session)
+static void iscsi_logout(iscsi_session_t * session)
 {
 	struct iscsi_logout logout_req;
 	struct iscsi_logout_rsp logout_resp;
@@ -1128,7 +994,7 @@ iscsi_logout_and_disconnect(iscsi_sessio
 	if (!rc) {
 		log_error(
 		       "iscsid: iscsi_logout - failed to send logout PDU.");
-		goto done;
+		return;
 	}
 
 	/*
@@ -1138,117 +1004,362 @@ iscsi_logout_and_disconnect(iscsi_sessio
 	rc = iscsi_io_recv_pdu(&session->conn[0],
 		(struct iscsi_hdr *)&logout_resp, ISCSI_DIGEST_NONE, NULL,
 		0, ISCSI_DIGEST_NONE, 1);
-	if (!rc) {
+	if (rc < 0) {
 		log_error("iscsid: logout - failed to receive logout resp");
-		goto done;
+		return;
 	}
 	if (logout_resp.response != ISCSI_LOGOUT_SUCCESS) {
 		log_error("iscsid: logout failed - response = 0x%x",
 		       logout_resp.response);
 	}
+}
+#endif /* Unused */
+
+static void iscsi_destroy_session(struct iscsi_session *session)
+{
+	struct iscsi_transport *t = session->t;
+	struct iscsi_conn *conn = &session->conn[0];
+	int rc;
+
+	if (session->id == -1)
+		return;
+
+	if (!(t->caps & CAP_TEXT_NEGO)) {
+		iscsi_io_disconnect(&session->conn[0]);
+		goto done;
+	}
 
+	log_debug(2, "%s ep disconnect", __FUNCTION__);
+	t->template->ep_disconnect(conn);
+
+	log_debug(2, "stop conn");
+	rc = ipc->stop_conn(session->t->handle, session->id,
+			   conn->id, STOP_CONN_TERM);
+	if (rc) {
+		log_error("Could not stop conn %d:%d cleanly (err %d)\n",
+			  session->id, conn->id, rc);
+		goto done;
+        }
+
+	log_debug(2, "%s destroy conn", __FUNCTION__);
+        rc = ipc->destroy_conn(session->t->handle, session->id, conn->id);
+	if (rc) {
+		log_error("Could not safely destroy conn %d:%d (err %d)",
+			  session->id, conn->id, rc);
+		goto done;
+	}
+
+	log_debug(2, "%s destroy session", __FUNCTION__);
+	rc = ipc->destroy_session(session->t->handle, session->id);
+	if (rc)
+		log_error("Could not safely destroy session %d (err %d)",
+			  session->id, rc);
 done:
+	if (conn->socket_fd >= 0) {
+		ipc->ctldev_close();
+		conn->socket_fd = -1;
+	}
+	session->id = -1;
+}
+
+static int iscsi_create_leading_conn(struct iscsi_session *session)
+{
+	struct iface_rec *iface = &session->nrec.iface;
+	struct iscsi_transport *t = session->t;
+	struct iscsi_conn *conn = &session->conn[0];
+	uint32_t host_no;
+	int rc, sleep_count = 0;
+
+	if (!(t->caps & CAP_TEXT_NEGO)) {
+		/*
+		 * If the LLD does not support TEXT PDUs then we do
+		 * discovery in userspace.
+		 */
+		session->use_ipc = 0;
+
+		if (!iscsi_io_connect(conn))
+			return ISCSI_ERR_TRANS;
+
+		session->id = 1;
+		return 0;
+	}
+	session->use_ipc = 1;
+
 	/*
-	 * Close the socket.
+	 * for software this is the tcp socket fd set in iscsi_io_connect
+	 * and for offload this is the iscsi netlink socket fd
 	 */
-	iscsi_io_disconnect(&session->conn[0]);
+	conn->socket_fd = ipc->ctldev_open();
+	if (conn->socket_fd < 0) {
+		log_error("Could not open netlink interface (err %d)\n",
+			  errno);
+		return ISCSI_ERR_INTERNAL;
+	}
+
+	host_no = iscsi_sysfs_get_host_no_from_hwinfo(iface, &rc);
+	if (!rc) {
+		/*
+		 * if the netdev or mac was set, then we are going to want
+		 * to want to bind the all the conns/eps to a specific host
+		 * if offload is used.
+		 */
+		session->conn[0].bind_ep = 1;
+		session->hostno = host_no;
+	}
+
+	rc = iscsi_host_set_net_params(iface, session);
+	if (rc) {
+		log_error("Could not set host net params (err %d)\n",
+			  rc);
+		rc = ISCSI_ERR_INTERNAL;
+		goto close_ipc;
+	}
+
+	/* create interconnect endpoint */
+	log_debug(2, "%s discovery ep connect\n", __FUNCTION__);
+	rc = t->template->ep_connect(conn, 1);
+	if (rc < 0) {
+		rc = ISCSI_ERR_TRANS;
+		goto close_ipc;
+	}
+
+	do {
+		rc = t->template->ep_poll(conn, 1);
+		if (rc < 0) {
+			rc = ISCSI_ERR_TRANS;
+			goto disconnect;
+		} else if (rc == 0) {
+			if (sleep_count == conn->login_timeout) {
+				rc = ISCSI_ERR_TRANS_TIMEOUT;
+				goto disconnect;
+			}
+			sleep_count++;
+			sleep(1);
+		} else
+			break;
+	} while (1);
+
+	log_debug(2, "%s discovery create session\n", __FUNCTION__);
+	/* create kernel structs */
+        rc = ipc->create_session(session->t->handle,
+				 conn->transport_ep_handle, 1, 32, 1,
+				 &session->id, &host_no);
+	if (rc) {
+		log_error("Could not create kernel session (err %d).\n", rc);
+		rc = ISCSI_ERR_INTERNAL;
+		goto disconnect;
+	}
+	log_debug(2, "%s discovery created session %u\n", __FUNCTION__,
+		  session->id);
+	session->isid[3] = session->id;
+
+	log_debug(2, "%s discovery create conn\n", __FUNCTION__);
+	rc = ipc->create_conn(t->handle, session->id, conn->id, &conn->id);
+	if (rc) {
+		log_error("Could not create connection (err %d)", rc);
+		rc = ISCSI_ERR_INTERNAL;
+		goto disconnect;
+	}
+
+	log_debug(2, "%s discovery bind conn\n", __FUNCTION__);
+	if (ipc->bind_conn(t->handle, session->id, conn->id,
+			   conn->transport_ep_handle, (conn->id == 0), &rc) ||
+	    rc) {
+		log_error("Could not bind conn %d:%d to session %d, "
+			  "(err %d)", session->id, conn->id,
+			  session->id, rc);
+		rc = ISCSI_ERR_INTERNAL;
+		goto disconnect;
+	}
+
+	/* all set */
+	return 0;
+
+disconnect:
+	t->template->ep_disconnect(conn);
+
+	if (session->id != -1 &&
+	    iscsi_sysfs_session_has_leadconn(session->id)) {
+		if (ipc->destroy_conn(session->t->handle, session->id,
+				       conn->id))
+			log_error("Could not safely destroy connection %d:%d",
+				  session->id, conn->id);
+	}
+
+	if (session->id != -1) {
+		if (ipc->destroy_session(session->t->handle, session->id))
+			log_error("Could not safely destroy session %d",
+				  session->id);
+		session->id = -1;
+	}
+
+close_ipc:
+	if (conn->socket_fd >= 0) {
+		ipc->ctldev_close();
+		conn->socket_fd = -1;
+	}
+
+	log_error("Connection to discovery portal %s failed: %s",
+		  conn->host, iscsi_err_to_str(rc));
+	return rc;
 }
 
-int discovery_sendtargets(void *fndata, struct iface_rec *iface,
-			  struct list_head *rec_list)
+static struct iscsi_ev_context *
+iscsi_ev_context_get(struct iscsi_conn *conn, int ev_size)
 {
-	discovery_rec_t *drec = fndata;
-	iscsi_session_t *session;
+	log_debug(2, "%s: ev_size %d\n", __FUNCTION__, ev_size);
+
+	ipc_ev_context.data = calloc(1, ev_size);
+	if (!ipc_ev_context.data)
+		return NULL;
+
+	return &ipc_ev_context;
+}
+
+static void iscsi_ev_context_put(struct iscsi_ev_context *ev_context)
+{
+	if (ev_context->data)
+		free(ev_context->data);
+	ev_context->data = NULL;
+}
+
+static int iscsi_sched_ev_context(struct iscsi_ev_context *ev_context,
+				  struct iscsi_conn *conn, unsigned long tmo,
+				  int event)
+{
+	if (event == EV_CONN_RECV_PDU || event == EV_CONN_LOGIN) {
+		conn->recv_context = ev_context;
+		return 0;
+	}
+
+	return -EIO;
+}
+
+static struct iscsi_ipc_ev_clbk ipc_clbk = {
+        .get_ev_context         = iscsi_ev_context_get,
+        .put_ev_context         = iscsi_ev_context_put,
+        .sched_ev_context       = iscsi_sched_ev_context,
+};
+
+static int iscsi_wait_for_login(struct iscsi_conn *conn)
+{
+	struct iscsi_session *session = conn->session;
+	struct iscsi_transport *t = session->t;
 	struct pollfd pfd;
-	struct iscsi_hdr pdu_buffer;
-	struct iscsi_hdr *pdu = &pdu_buffer;
-	char *data = NULL;
-	int active = 0, valid_text = 0;
 	struct timeval connection_timer;
-	int timeout;
-	int rc;
-	struct str_buffer sendtargets;
-	uint8_t status_class = 0, status_detail = 0;
-	unsigned int login_failures = 0, data_len;
-	int login_delay = 0;
-	struct sockaddr_storage ss;
-	char host[NI_MAXHOST], serv[NI_MAXSERV], default_port[NI_MAXSERV];
-	struct iscsi_sendtargets_config *config = &drec->u.sendtargets;
+	int timeout, rc;
+	uint32_t conn_state;
+	int status = 0;
 
-	/* initial setup */
-	log_debug(1, "starting sendtargets discovery, address %s:%d, ",
-		 drec->address, drec->port);
-	memset(&pdu_buffer, 0, sizeof (pdu_buffer));
-	clear_timer(&connection_timer);
+	if (!(t->caps & CAP_LOGIN_OFFLOAD))
+		return 0;
 
-	/* allocate a new session, and initialize default values */
-	session = init_new_session(config, iface);
-	if (session == NULL) {
-		log_error("Discovery process to %s:%d failed to "
-			  "create a discovery session.",
-			  drec->address, drec->port);
-		return 1;
-	}
+	iscsi_timer_set(&connection_timer, conn->active_timeout);
 
-	log_debug(4, "sendtargets discovery to %s:%d using "
-		 "isid 0x%02x%02x%02x%02x%02x%02x",
-		 drec->address, drec->port, session->isid[0],
-		 session->isid[1], session->isid[2], session->isid[3],
-		 session->isid[4], session->isid[5]);
+	/* prepare to poll */
+	memset(&pfd, 0, sizeof(pfd));
+	pfd.fd = conn->socket_fd;
+	pfd.events = POLLIN | POLLPRI;
 
-	/* allocate data buffers for SendTargets data */
-	data = malloc(session->conn[0].max_recv_dlength);
-	if (!data) {
-		rc = 1;
-		goto free_session;
-	}
-	data_len = session->conn[0].max_recv_dlength;
+	timeout = iscsi_timer_msecs_until(&connection_timer);
 
-	str_init_buffer(&sendtargets, 0);
+login_repoll:
+	log_debug(4, "discovery login process polling fd %d, "
+		 "timeout in %f seconds", pfd.fd, timeout / 1000.0);
 
-	sprintf(default_port, "%d", drec->port);
-	/* resolve the DiscoveryAddress to an IP address */
-	if (resolve_address(drec->address, default_port, &ss)) {
-		log_error("cannot resolve host name %s", drec->address);
-		rc = 1;
-		goto free_sendtargets;
+	pfd.revents = 0;
+	rc = poll(&pfd, 1, timeout);
+
+	log_debug(7, "discovery login process returned from poll, rc %d", rc);
+
+	if (iscsi_timer_expired(&connection_timer)) {
+		log_warning("Discovery login session timed out.");
+		rc = ISCSI_ERR_INTERNAL;
+		goto done;
 	}
 
-	log_debug(4, "discovery timeouts: login %d, reopen_cnt %d, auth %d.",
-		 session->conn[0].login_timeout, session->reopen_cnt,
-		 session->conn[0].auth_timeout);
+	if (rc > 0) {
+		if (pfd.revents & (POLLIN | POLLPRI)) {
+			timeout = iscsi_timer_msecs_until(&connection_timer);
+			status = ipc->recv_conn_state(conn, &conn_state);
+			if (status == -EAGAIN)
+				goto login_repoll;
+			else if (status < 0) {
+				rc = ISCSI_ERR_TRANS;
+				goto done;
+			}
 
-	/* setup authentication variables for the session*/
-	rc = setup_authentication(session, drec, config);
-	if (rc == 0) {
-		rc = 1;
-		goto free_sendtargets;
+			if (conn_state != ISCSI_CONN_STATE_LOGGED_IN)
+				rc = ISCSI_ERR_TRANS;
+			else
+				rc = 0;
+			goto done;
+		}
+
+		if (pfd.revents & POLLHUP) {
+			log_warning("discovery session"
+				    "terminating after hangup");
+			 rc = ISCSI_ERR_TRANS;
+			 goto done;
+		}
+
+		if (pfd.revents & POLLNVAL) {
+			log_warning("discovery POLLNVAL");
+			rc = ISCSI_ERR_INTERNAL;
+			goto done;
+		}
+
+		if (pfd.revents & POLLERR) {
+			log_warning("discovery POLLERR");
+			rc = ISCSI_ERR_INTERNAL;
+			goto done;
+		}
+	} else if (rc < 0) {
+		log_error("Login poll error");
+		rc = ISCSI_ERR_INTERNAL;
+		goto done;
 	}
 
+done:
+	return rc;
+}
+
+static int iscsi_create_session(struct iscsi_session *session,
+				struct iscsi_sendtargets_config *config,
+				char *data, unsigned int data_len)
+{
+	struct iscsi_conn *conn = &session->conn[0];
+	int login_status, rc = 0, login_delay = 0;
+	uint8_t status_class = 0, status_detail = 0;
+	unsigned int login_failures = 0;
+	char serv[NI_MAXSERV];
+	struct iscsi_transport *t = session->t;
+
 set_address:
 	/*
 	 * copy the saved address to the session,
 	 * undoing any temporary redirect
 	 */
-	session->conn[0].saddr = ss;
+	conn->saddr = conn->failback_saddr;
 
 reconnect:
-
+	/* fix decrement and test */
 	if (--session->reopen_cnt < 0) {
-		log_error("connection login retries (reopen_max %d) exceeded",
+		log_error("connection login retries (reopen_max) %d exceeded",
 			  config->reopen_max);
-		rc = 1;
-		goto free_sendtargets;
+		goto login_failed;
 	}
 
 redirect_reconnect:
-
-	iscsi_io_disconnect(&session->conn[0]);
-
 	session->cmdsn = 1;
 	session->itt = 1;
 	session->portal_group_tag = PORTAL_GROUP_TAG_UNKNOWN;
 
+	/*
+	 * On reconnect, just destroy the kernel structs and start over.
+	 */
+	iscsi_destroy_session(session);
+
 	/* slowly back off the frequency of login attempts */
 	if (login_failures == 0)
 		login_delay = 0;
@@ -1263,47 +1374,47 @@ redirect_reconnect:
 	else
 		login_delay = 60;	/* after 2 minutes, try once a minute */
 
+	getnameinfo((struct sockaddr *) &conn->saddr,
+		    sizeof(conn->saddr), conn->host,
+		    sizeof(conn->host), serv, sizeof(serv),
+		    NI_NUMERICHOST|NI_NUMERICSERV);
+
 	if (login_delay) {
-		log_debug(4, "discovery session to %s:%d sleeping for %d "
+		log_debug(4, "discovery session to %s:%s sleeping for %d "
 			 "seconds before next login attempt",
-			 drec->address, drec->port, login_delay);
+			 conn->host, serv, login_delay);
 		sleep(login_delay);
 	}
-
-	getnameinfo((struct sockaddr *) &session->conn[0].saddr,
-		    sizeof(session->conn[0].saddr), host,
-		    sizeof(host), serv, sizeof(serv),
-		    NI_NUMERICHOST|NI_NUMERICSERV);
-
-	if (!iscsi_io_connect(&session->conn[0])) {
-		log_error("connection to discovery address %s "
-			  "failed", host);
-
+	rc = iscsi_create_leading_conn(session);
+	if (rc) {
 		login_failures++;
-		/* If a temporary redirect sent us to something unreachable,
-		 * we want to go back to the original IP address, so make sure
-		 * we reset the session's IP.
-		 */
-		goto set_address;
+		goto reconnect;
 	}
 
-	log_debug(1, "connected to discovery address %s", host);
+	log_debug(1, "connected to discovery address %s", conn->host);
 
-	log_debug(4, "discovery session to %s:%d starting iSCSI login on fd %d",
-		 drec->address, drec->port, session->conn[0].socket_fd);
+	log_debug(4, "discovery session to %s:%s starting iSCSI login",
+		 conn->host, serv);
 
-	/* In case of discovery, we using socket's descriptor as ctrl. */
-	session->ctrl_fd = session->conn[0].socket_fd;
-	session->conn[0].session = session;
+	/*
+	 * Need to re-init settings because a previous login could
+	 * have set them to what was negotiated for.
+	 */
+	iscsi_copy_operational_params(&session->conn[0], &config->session_conf,
+				      &config->conn_conf);
+
+	if ((session->t->caps & CAP_LOGIN_OFFLOAD))
+		goto start_conn;
 
 	status_class = 0;
 	status_detail = 0;
+	rc = ISCSI_ERR_LOGIN;
 
 	memset(data, 0, data_len);
-	rc = iscsi_login(session, 0, data, data_len,
-			 &status_class, &status_detail);
+	login_status = iscsi_login(session, 0, data, data_len,
+				   &status_class, &status_detail);
 
-	switch (rc) {
+	switch (login_status) {
 	case LOGIN_OK:
 	case LOGIN_REDIRECT:
 		break;
@@ -1311,8 +1422,7 @@ redirect_reconnect:
 	case LOGIN_IO_ERROR:
 	case LOGIN_REDIRECTION_FAILED:
 		/* try again */
-		log_warning("retrying discovery login to %s", host);
-		iscsi_io_disconnect(&session->conn[0]);
+		log_warning("retrying discovery login to %s", conn->host);
 		login_failures++;
 		goto set_address;
 
@@ -1322,16 +1432,16 @@ redirect_reconnect:
 	case LOGIN_AUTHENTICATION_FAILED:
 	case LOGIN_VERSION_MISMATCH:
 	case LOGIN_INVALID_PDU:
-		log_error("discovery login to %s failed, giving up", host);
-		iscsi_io_disconnect(&session->conn[0]);
-		rc = 1;
-		goto free_sendtargets;
+		log_error("discovery login to %s failed, giving up %d",
+			  conn->host, login_status);
+		rc = ISCSI_ERR_FATAL_LOGIN;
+		goto login_failed;
 	}
 
 	/* check the login status */
 	switch (status_class) {
 	case ISCSI_STATUS_CLS_SUCCESS:
-		log_debug(4, "discovery login success to %s", host);
+		log_debug(4, "discovery login success to %s", conn->host);
 		login_failures = 0;
 		break;
 	case ISCSI_STATUS_CLS_REDIRECT:
@@ -1343,14 +1453,16 @@ redirect_reconnect:
 		case ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP:
 			log_warning(
 				"discovery login temporarily redirected to "
-				"%s port %s", host, serv);
+				"%s port %s", conn->host, serv);
 			goto redirect_reconnect;
 		case ISCSI_LOGIN_STATUS_TGT_MOVED_PERM:
 			log_warning(
 				"discovery login permanently redirected to "
-				"%s port %s", host, serv);
+				"%s port %s", conn->host, serv);
 			/* make the new address permanent */
-			ss = session->conn[0].saddr;
+			memset(&conn->failback_saddr, 0,
+				sizeof(struct sockaddr_storage));
+			conn->failback_saddr = conn->saddr;
 			goto redirect_reconnect;
 		default:
 			log_error(
@@ -1361,32 +1473,133 @@ redirect_reconnect:
 		}
 		break;
 	case ISCSI_STATUS_CLS_INITIATOR_ERR:
-		log_error(
-			"discovery login to %s rejected: "
-			"initiator error (%02x/%02x), non-retryable, giving up",
-			host, status_class, status_detail);
-		iscsi_io_disconnect(&session->conn[0]);
-		rc = 1;
-		goto free_sendtargets;
+		switch (status_detail) {
+		case ISCSI_LOGIN_STATUS_AUTH_FAILED:
+		case ISCSI_LOGIN_STATUS_TGT_FORBIDDEN:
+			log_error("discovery login to %s rejected: "
+				  "initiator failed authorization\n",
+				 conn->host);
+			rc = ISCSI_ERR_LOGIN_AUTH_FAILED;
+			goto login_failed;
+		default:
+			log_error("discovery login to %s rejected: initiator "
+				  "error (%02x/%02x), non-retryable, giving up",
+				  conn->host, status_class, status_detail);
+			rc = ISCSI_ERR_FATAL_LOGIN;
+		}
+		goto login_failed;
 	case ISCSI_STATUS_CLS_TARGET_ERR:
 		log_error(
 			"discovery login to %s rejected: "
 			"target error (%02x/%02x)",
-			host, status_class, status_detail);
-		iscsi_io_disconnect(&session->conn[0]);
+			conn->host, status_class, status_detail);
 		login_failures++;
 		goto reconnect;
 	default:
 		log_error(
 			"discovery login to %s failed, response "
 			"with unknown status class 0x%x, detail 0x%x",
-			host,
+			conn->host,
 			status_class, status_detail);
-		iscsi_io_disconnect(&session->conn[0]);
 		login_failures++;
 		goto reconnect;
 	}
 
+	if (!(t->caps & CAP_TEXT_NEGO))
+		return 0;
+
+start_conn:
+	log_debug(2, "%s discovery set params\n", __FUNCTION__);
+	rc = iscsi_session_set_params(conn);
+	if (rc) {
+		log_error("Could not set iscsi params for conn %d:%d (err "
+			  "%d)\n", session->id, conn->id, rc);
+		rc = ISCSI_ERR_INTERNAL;
+		goto login_failed;
+	}
+
+	log_debug(2, "%s discovery start conn\n", __FUNCTION__);
+	if (ipc->start_conn(t->handle, session->id, conn->id, &rc) || rc) {
+		log_error("Cannot start conn %d:%d (err %d)",
+			  session->id, conn->id, rc);
+		rc = ISCSI_ERR_INTERNAL;
+		goto login_failed;
+	}
+
+	rc = iscsi_wait_for_login(conn);
+	if (!rc)
+		return 0;
+
+login_failed:
+	iscsi_destroy_session(session);
+	return rc;
+}
+
+int discovery_sendtargets(void *fndata, struct iface_rec *iface,
+			  struct list_head *rec_list)
+{
+	discovery_rec_t *drec = fndata;
+	iscsi_session_t *session;
+	struct pollfd pfd;
+	struct iscsi_hdr pdu_buffer;
+	struct iscsi_hdr *pdu = &pdu_buffer;
+	char *data = NULL;
+	int active = 0, valid_text = 0;
+	struct timeval connection_timer;
+	int timeout;
+	int rc = 0;
+	struct str_buffer sendtargets;
+	unsigned int data_len;
+	struct iscsi_sendtargets_config *config = &drec->u.sendtargets;
+
+	/* initial setup */
+	log_debug(1, "starting sendtargets discovery, address %s:%d, ",
+		 drec->address, drec->port);
+	memset(&pdu_buffer, 0, sizeof (pdu_buffer));
+	iscsi_timer_clear(&connection_timer);
+
+	/* allocate a new session, and initialize default values */
+	session = iscsi_alloc_session(config, iface, &rc);
+	if (rc)
+		return rc;
+
+	ipc_ev_context.conn = &session->conn[0];
+	ipc_register_ev_callback(&ipc_clbk);
+
+	log_debug(4, "sendtargets discovery to %s:%d using "
+		 "isid 0x%02x%02x%02x%02x%02x%02x",
+		 drec->address, drec->port, session->isid[0],
+		 session->isid[1], session->isid[2], session->isid[3],
+		 session->isid[4], session->isid[5]);
+
+	/* allocate data buffers for SendTargets data */
+	data = malloc(session->conn[0].max_recv_dlength);
+	if (!data) {
+		rc = ISCSI_ERR_NOMEM;
+		goto free_session;
+	}
+	data_len = session->conn[0].max_recv_dlength;
+
+	str_init_buffer(&sendtargets, 0);
+
+	/* resolve the DiscoveryAddress to an IP address */
+	rc = iscsi_setup_portal(&session->conn[0], drec->address,
+				drec->port);
+	if (rc) {
+		log_error("cannot resolve host name %s", drec->address);
+		goto free_sendtargets;
+	}
+
+	log_debug(4, "discovery timeouts: login %d, reopen_cnt %d, auth %d.",
+		 session->conn[0].login_timeout, session->reopen_cnt,
+		 session->conn[0].auth_timeout);
+
+reconnect:
+	rc = iscsi_create_session(session, &drec->u.sendtargets,
+				  data, data_len);
+	if (rc)
+		goto free_sendtargets;
+
 	/* reinitialize */
 	str_truncate_buffer(&sendtargets, 0);
 
@@ -1397,7 +1610,7 @@ redirect_reconnect:
 	active = 1;
 
 	/* set timeouts */
-	set_timer(&connection_timer, session->conn[0].active_timeout);
+	iscsi_timer_set(&connection_timer, session->conn[0].active_timeout);
 
 	/* prepare to poll */
 	memset(&pfd, 0, sizeof (pfd));
@@ -1405,7 +1618,7 @@ redirect_reconnect:
 	pfd.events = POLLIN | POLLPRI;
 
 repoll:
-	timeout = msecs_until(&connection_timer);
+	timeout = iscsi_timer_msecs_until(&connection_timer);
 	/* block until we receive a PDU, a TCP FIN, a TCP RST,
 	 * or a timeout
 	 */
@@ -1422,31 +1635,30 @@ repoll:
 		 "discovery process to %s:%d returned from poll, rc %d",
 		 drec->address, drec->port, rc);
 
-	if (timer_expired(&connection_timer)) {
-		log_warning("discovery session to %s:%d session "
-			    "logout, connection timer expired",
+	if (iscsi_timer_expired(&connection_timer)) {
+		log_warning("Discovery session to %s:%d timed out.",
 			    drec->address, drec->port);
-			    iscsi_logout_and_disconnect(session);
-		rc = 1;
-		goto free_sendtargets;
+		rc = ISCSI_ERR_TRANS_TIMEOUT;
+		goto reconnect;
 	}
 
 	if (rc > 0) {
 		if (pfd.revents & (POLLIN | POLLPRI)) {
-			timeout = msecs_until(&connection_timer);
+			timeout = iscsi_timer_msecs_until(&connection_timer);
 
-			memset(data, 0, data_len);
-			if (!iscsi_io_recv_pdu(&session->conn[0],
-					       pdu, ISCSI_DIGEST_NONE, data,
-			     		       data_len, ISCSI_DIGEST_NONE,
-					       timeout)) {
+			rc = iscsi_io_recv_pdu(&session->conn[0],
+					        pdu, ISCSI_DIGEST_NONE, data,
+					        data_len, ISCSI_DIGEST_NONE,
+					        timeout);
+			if (rc == -EAGAIN)
+				goto repoll;
+			else if (rc < 0) {
 				log_debug(1, "discovery session to "
 					  "%s:%d failed to recv a PDU "
 					  "response, terminating",
 					   drec->address,
 					   drec->port);
-				iscsi_io_disconnect(&session->conn[0]);
-				rc = 1;
+				rc = ISCSI_ERR_PDU_TIMEOUT;
 				goto free_sendtargets;
 			}
 
@@ -1455,14 +1667,13 @@ repoll:
 			 */
 			rc = process_recvd_pdu(pdu, drec, rec_list,
 					       session, &sendtargets,
-					       default_port,
 					       &active, &valid_text, data);
 			if (rc == DISCOVERY_NEED_RECONNECT)
 				goto reconnect;
 
 			/* reset timers after receiving a PDU */
 			if (active) {
-				set_timer(&connection_timer,
+				iscsi_timer_set(&connection_timer,
 				       session->conn[0].active_timeout);
 				goto repoll;
 			}
@@ -1472,8 +1683,7 @@ repoll:
 			log_warning("discovery session to %s:%d "
 				    "terminating after hangup",
 				     drec->address, drec->port);
-			iscsi_io_disconnect(&session->conn[0]);
-			rc = 1;
+			rc = ISCSI_ERR_TRANS;
 			goto free_sendtargets;
 		}
 
@@ -1489,18 +1699,9 @@ repoll:
 			goto reconnect;
 		}
 	} else if (rc < 0) {
-		if (errno == EINTR) {
-			/* if we got SIGHUP, reconnect and rediscover */
-			if (rediscover) {
-				rediscover = 0;
-				log_debug(1, "rediscovery requested");
-				goto reconnect;
-			}
-		} else {
-			log_error("poll error");
-			rc = 1;
-			goto free_sendtargets;
-		}
+		log_error("poll error");
+		rc = ISCSI_ERR;
+		goto free_sendtargets;
 	}
 
 	log_debug(1, "discovery process to %s:%d exiting",
@@ -1510,8 +1711,9 @@ repoll:
 free_sendtargets:
 	str_free_buffer(&sendtargets);
 	free(data);
+	iscsi_destroy_session(session);
 free_session:
-	free(session);
+	iscsi_free_session(session);
 	return rc;
 }
 
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/discoveryd.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/discoveryd.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/discoveryd.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/discoveryd.c	2011-08-14 16:48:25.000000000 -0500
@@ -44,6 +44,7 @@
 #include "isns.h"
 #include "paths.h"
 #include "message.h"
+#include "iscsi_err.h"
 
 #define DISC_DEF_POLL_INVL	30
 
@@ -242,12 +243,12 @@ static int isns_build_objs(isns_portal_i
 		nportals = isns_get_nr_portals();
 		log_debug(4, "got %d portals", nportals);
 		if (!nportals)
-			return ENODEV;
+			return ISCSI_ERR_NO_OBJS_FOUND;
 
 		iflist = calloc(nportals, sizeof(isns_portal_info_t));
 		if (!iflist) {
 			log_error("Unable to allocate %d portals.", nportals);
-			return ENOMEM;
+			return ISCSI_ERR_NOMEM;
 		}
 
 		nportals = isns_enumerate_portals(iflist, nportals);
@@ -255,7 +256,7 @@ static int isns_build_objs(isns_portal_i
 			log_error("Unable to enumerate portals - "
 				  "no usable interfaces found\n");
 			free(iflist);
-			return ENODEV;
+			return ISCSI_ERR_NO_OBJS_FOUND;
 		}
 		for (i = 0; i < nportals; ++i) {
 			iflist[i].addr.sin6_port = portal_info->addr.sin6_port;
@@ -267,7 +268,7 @@ static int isns_build_objs(isns_portal_i
 	if (!isns_entity_id) {
 		isns_entity_id = calloc(1, 256);
 		if (!isns_entity_id)
-			return ENOMEM;
+			return ISCSI_ERR_NOMEM;
 
 		rc = getnameinfo((struct sockaddr *) &portal_info->addr,
 				 sizeof(portal_info->addr),
@@ -277,14 +278,14 @@ static int isns_build_objs(isns_portal_i
 			isns_entity_id = NULL;
 
 			log_error("Could not get hostname for EID.");
-			return EIO;
+			return ISCSI_ERR;
 		}
 	}
 
 	entity = isns_create_entity(ISNS_ENTITY_PROTOCOL_ISCSI, isns_entity_id);
 	if (!entity) {
 		log_error("Could not create iSNS entity.");
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	}
 	isns_object_list_append(objs, entity);
 
@@ -293,14 +294,14 @@ static int isns_build_objs(isns_portal_i
 
 		portal = isns_create_portal(portal_info, entity);
 		if (!portal) {
-			rc = ENOMEM;
+			rc = ISCSI_ERR_NOMEM;
 			goto fail;
 		}
 		isns_object_list_append(objs, portal);
 
 		if (!isns_object_set_uint32(portal, ISNS_TAG_SCN_PORT,
 				isns_portal_tcpudp_port(portal_info))) {
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			goto fail;
 		}
 	}
@@ -310,7 +311,7 @@ static int isns_build_objs(isns_portal_i
 						  ISNS_ISCSI_INITIATOR_MASK,
 						  NULL);
 		if (!inode) {
-			rc = ENOMEM;
+			rc = ISCSI_ERR_NOMEM;
 			goto fail;
 		}
 		isns_object_list_append(objs, inode);		
@@ -366,7 +367,6 @@ static int isns_disc_new_portals(const c
 	qry_data.targetname = targetname;
 	qry_data.iname = iname;
 
-log_error("isns_disc_new_portals");
 	iface_link_ifaces(&ifaces);
 	rc = idbm_bind_ifaces_to_nodes(isns_query_node, &qry_data, &ifaces,
 				       &rec_list);
@@ -559,7 +559,7 @@ static int isns_setup_registration_refre
 		log_error("Unable to extract object list from "
                            "registration response: %s\n",
                            isns_strerror(status));
-		return EIO;
+		return ISCSI_ERR;
 	}
 
 	for (i = 0; i < objs.iol_count; ++i) {
@@ -578,7 +578,7 @@ static int isns_setup_registration_refre
 
 	refresh_data = calloc(1, sizeof(*refresh_data));
 	if (!refresh_data) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_objs;
 	}
 	INIT_LIST_HEAD(&refresh_data->list);
@@ -654,7 +654,7 @@ static int isns_register_objs(isns_clien
 
 	reg = isns_create_registration(clnt, entity);
 	if (!reg)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	for (i = 0; i < objs->iol_count; ++i)
 		isns_registration_add_object(reg, objs->iol_data[i]);
@@ -664,7 +664,7 @@ static int isns_register_objs(isns_clien
 	if (status != ISNS_SUCCESS) {
 		log_error("Could not register with iSNS server: %s",
 			  isns_strerror(status));
-		rc = EIO;
+		rc = ISCSI_ERR;
 		goto free_reg;
 	}
 	log_debug(4, "Registered objs");
@@ -687,7 +687,7 @@ static int isns_register_objs(isns_clien
 
 		if (!reg) {
 			isns_cancel_refresh_timers();
-			rc = ENOMEM;
+			rc = ISCSI_ERR_NOMEM;
 			goto done;
 		}
 
@@ -703,7 +703,7 @@ static int isns_register_objs(isns_clien
 			 */
 			if (poll_inval < 0) {
 				isns_cancel_refresh_timers();
-				rc = EIO;
+				rc = ISCSI_ERR;
 				break;
 			}
 		}
@@ -727,7 +727,7 @@ static int isns_scn_register(isns_socket
 	clnt = isns_create_default_client(NULL);
 	if (!clnt) {
 		log_error("iSNS setup failed. Could not connect to server.");
-		return ENOTCONN;
+		return ISCSI_ERR_TRANS;
 	}
 	isns_socket_set_disconnect_fatal(clnt->ic_socket);
 
@@ -735,7 +735,7 @@ static int isns_scn_register(isns_socket
 
 	if (!isns_socket_get_portal_info(svr_sock, &portal_info)) {
 		log_error("Could not get portal info for iSNS registration.");
-		rc = ENODEV;
+		rc = ISCSI_ERR_NO_OBJS_FOUND;
 		goto destroy_clnt;
 	}
 
@@ -797,7 +797,7 @@ static int isns_create_node_list(const c
 	if (def_iname) {
 		node = isns_create_node(def_iname);
 		if (!node) {
-			rc = ENOMEM;
+			rc = ISCSI_ERR_NOMEM;
 			goto fail;
 		}
 		list_add_tail(&node->list, &isns_initiators);
@@ -808,7 +808,7 @@ static int isns_create_node_list(const c
 		    !isns_lookup_node(iface->iname)) {
 			node = isns_create_node(iface->iname);
 			if (!node) {
-				rc = ENOMEM;
+				rc = ISCSI_ERR_NOMEM;
 				goto fail;
 			}
 			list_add_tail(&node->list, &isns_initiators);
@@ -943,7 +943,7 @@ static int isns_eventd(const char *def_i
 	isns_create_node_list(def_iname);
 	if (list_empty(&isns_initiators)) {
 		log_error("iSNS registration failed. Initiatorname not set.");
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	/* use def_iname or if not set the first iface's iname for the src */
@@ -955,7 +955,7 @@ static int isns_eventd(const char *def_i
 	isns_config.ic_control_socket = ISNS_EVENTD_CTL;
 
 	if (discovery_isns_set_servername(disc_addr, port)) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto fail;
 	}
 
@@ -964,13 +964,13 @@ static int isns_eventd(const char *def_i
 	db = isns_db_open(NULL);
 	if (!db) {
 		log_error("iSNS setup failed. Could not create db.");
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto fail;
 	}
 	svr = isns_create_server(node->source, db, &isns_callback_service_ops);
 	if (!svr) {
 		log_error("iSNS setup failed. Could not create server.");
-		rc = ENOTCONN;
+		rc = ISCSI_ERR_TRANS;
 		goto fail;
 	}
 	isns_server_set_scn_callback(svr, isns_scn_callback);
@@ -978,7 +978,7 @@ static int isns_eventd(const char *def_i
 	svr_sock = isns_create_server_socket(NULL, NULL, AF_INET6, SOCK_DGRAM);
 	if (!svr_sock) {
 		log_error("iSNS setup failed. Could not create server socket.");
-		rc = ENOTCONN;
+		rc = ISCSI_ERR_TRANS;
 		goto fail;
 	}
 
@@ -1077,7 +1077,7 @@ static int st_start(void *data, struct d
 	log_debug(1, "st_start %s:%d %d", drec->address, drec->port,
 		  drec->u.sendtargets.use_discoveryd);
 	if (!drec->u.sendtargets.use_discoveryd)
-		return ENOSYS;
+		return ISCSI_ERR_INVAL;
 
 	fork_disc(NULL, drec, drec->u.sendtargets.discoveryd_poll_inval,
 		  do_st_disc_and_login);
@@ -1094,7 +1094,7 @@ static int isns_start(void *data, struct
 	log_debug(1, "isns_start %s:%d %d", drec->address, drec->port,
 		  drec->u.isns.use_discoveryd);
 	if (!drec->u.isns.use_discoveryd)
-		return ENOSYS;
+		return ISCSI_ERR_INVAL;
 
 	fork_disc(data, drec, drec->u.isns.discoveryd_poll_inval, start_isns);
 	return 0;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/event_poll.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/event_poll.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/event_poll.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/event_poll.c	2011-08-14 16:48:25.000000000 -0500
@@ -35,6 +35,7 @@
 #include "iscsi_ipc.h"
 #include "actor.h"
 #include "initiator.h"
+#include "iscsi_err.h"
 
 static int reap_count;
 
@@ -174,5 +175,5 @@ void event_loop(struct iscsi_ipc *ipc, i
 		sysfs_cleanup();
 	}
 	if (shutdown_qtask)
-		mgmt_ipc_write_rsp(shutdown_qtask, MGMT_IPC_OK);
+		mgmt_ipc_write_rsp(shutdown_qtask, ISCSI_SUCCESS);
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/host.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/host.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/host.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/host.c	2011-08-14 16:48:25.000000000 -0500
@@ -33,6 +33,7 @@
 #include "transport.h"
 #include "initiator.h"
 #include "iface.h"
+#include "iscsi_err.h"
 
 static int match_host_to_session(void *data, struct session_info *info)
 {
@@ -117,6 +118,47 @@ static int host_info_print_flat(void *da
 	return 0;
 }
 
+static int print_host_iface(void *data, struct iface_rec *iface)
+{
+	char *prefix = data;
+
+	printf("%s**********\n", prefix);
+	printf("%sInterface:\n", prefix);
+	printf("%s**********\n", prefix);
+
+	printf("%sKernel Name: %s\n", prefix, iface->name);
+
+	if (!strlen(iface->ipaddress))
+		printf("%sIPaddress: %s\n", prefix, UNKNOWN_VALUE);
+	else if (strchr(iface->ipaddress, '.')) {
+		printf("%sIPaddress: %s\n", prefix, iface->ipaddress);
+		printf("%sGateway: %s\n", prefix, iface->gateway);
+		printf("%sSubnet: %s\n", prefix, iface->subnet_mask);
+		printf("%sBootProto: %s\n", prefix, iface->bootproto);
+	} else {
+		printf("%sIPaddress: [%s]\n", prefix, iface->ipaddress);
+		printf("%sIPaddress Autocfg: %s\n", prefix, iface->ipv6_autocfg);
+		printf("%sLink Local Address: [%s]\n", prefix,
+		       iface->ipv6_linklocal);
+		printf("%sLink Local Autocfg: %s\n", prefix,
+		       iface->linklocal_autocfg);
+		printf("%sRouter Address: [%s]\n", prefix, iface->ipv6_router);
+	}
+
+	printf("%sMTU: %u\n", prefix, iface->mtu);
+	printf("%svlan ID: %u\n", prefix, iface->vlan_id);
+	printf("%svlan priority: %u\n", prefix, iface->vlan_priority);
+	return 0;
+}
+
+static void print_host_ifaces(struct host_info *hinfo, char *prefix)
+{
+	int nr_found;
+
+	iscsi_sysfs_for_each_iface_on_host(prefix, hinfo->host_no, &nr_found,
+					   print_host_iface);
+}
+
 static int host_info_print_tree(void *data, struct host_info *hinfo)
 {
 	struct list_head sessions;
@@ -127,6 +169,7 @@ static int host_info_print_tree(void *da
 
 	INIT_LIST_HEAD(&sessions);
 
+
 	printf("Host Number: %u\n", hinfo->host_no);
 	if (!iscsi_sysfs_get_host_state(state, hinfo->host_no))
 		printf("\tState: %s\n", state);
@@ -134,6 +177,8 @@ static int host_info_print_tree(void *da
 		printf("\tState: Unknown\n");
 	print_host_info(&hinfo->iface, "\t");
 
+	print_host_ifaces(hinfo, "\t");
+
 	if (!session_info_flags)
 		return 0;
 
@@ -150,7 +195,7 @@ static int host_info_print_tree(void *da
 	printf("\tSessions:\n");
 	printf("\t*********\n");
 
-	session_info_print_tree(&sessions, "\t", session_info_flags);
+	session_info_print_tree(&sessions, "\t", session_info_flags, 0);
 	session_info_free_list(&sessions);
 	return 0;
 }
@@ -200,13 +245,16 @@ int host_info_print(int info_level, uint
 		break;
 	default:
 		log_error("Invalid info level %d. Try 0 - 4.", info_level);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	if (err) {
-		log_error("Can not get list of iSCSI hosts (%d)", err);
+		log_error("Can not get list of iSCSI hosts: %s",
+			  iscsi_err_to_str(err));
 		return err;
-	} else if (!num_found)
+	} else if (!num_found) {
 		log_error("No iSCSI hosts.");
+		return ISCSI_ERR_NO_OBJS_FOUND;
+	}
 	return 0;
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/idbm.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/idbm.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/idbm.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/idbm.c	2011-08-14 16:48:25.000000000 -0500
@@ -40,6 +40,7 @@
 #include "iface.h"
 #include "sysdeps.h"
 #include "fw_context.h"
+#include "iscsi_err.h"
 
 #define IDBM_HIDE	0    /* Hide parameter when print. */
 #define IDBM_SHOW	1    /* Show parameter when print. */
@@ -71,6 +72,28 @@ static struct idbm *db;
 	_n++; \
 } while(0)
 
+#define __recinfo_uint8(_key, _info, _rec, _name, _show, _n, _mod) do { \
+	_info[_n].type = TYPE_UINT8; \
+	strlcpy(_info[_n].name, _key, NAME_MAXVAL); \
+	snprintf(_info[_n].value, VALUE_MAXVAL, "%d", _rec->_name); \
+	_info[_n].data = &_rec->_name; \
+	_info[_n].data_len = sizeof(_rec->_name); \
+	_info[_n].visible = _show; \
+	_info[_n].can_modify = _mod; \
+	_n++; \
+} while (0)
+
+#define __recinfo_uint16(_key, _info, _rec, _name, _show, _n, _mod) do { \
+	_info[_n].type = TYPE_UINT16; \
+	strlcpy(_info[_n].name, _key, NAME_MAXVAL); \
+	snprintf(_info[_n].value, VALUE_MAXVAL, "%d", _rec->_name); \
+	_info[_n].data = &_rec->_name; \
+	_info[_n].data_len = sizeof(_rec->_name); \
+	_info[_n].visible = _show; \
+	_info[_n].can_modify = _mod; \
+	_n++; \
+} while (0)
+
 #define __recinfo_int_o2(_key,_info,_rec,_name,_show,_op0,_op1,_n, _mod) do { \
 	_info[_n].type = TYPE_INT_O; \
 	strlcpy(_info[_n].name, _key, NAME_MAXVAL); \
@@ -179,7 +202,7 @@ idbm_recinfo_discovery(discovery_rec_t *
 			      u.sendtargets.conn_timeo.active_timeout,
 			      IDBM_SHOW, num, 1);
 		__recinfo_int(DISC_ST_MAX_RECV_DLEN, ri, r,
-			      u.sendtargets.iscsi.MaxRecvDataSegmentLength,
+			      u.sendtargets.conn_conf.MaxRecvDataSegmentLength,
 			      IDBM_SHOW, num, 1);
 		break;
 	case DISCOVERY_TYPE_ISNS:
@@ -208,6 +231,8 @@ idbm_recinfo_node(node_rec_t *r, recinfo
 	__recinfo_int(NODE_TPGT, ri, r, tpgt, IDBM_SHOW, num, 0);
 	__recinfo_int_o3(NODE_STARTUP, ri, r, startup,
 			IDBM_SHOW, "manual", "automatic", "onboot", num, 1);
+	__recinfo_int_o2(NODE_LEADING_LOGIN, ri, r, leading_login, IDBM_SHOW,
+			 "No", "Yes", num, 1);
 	/*
 	 * Note: because we do not add the iface.iscsi_ifacename to
 	 * sysfs iscsiadm does some weird matching. We can change the iface
@@ -247,6 +272,8 @@ idbm_recinfo_node(node_rec_t *r, recinfo
 		      session.cmds_max, IDBM_SHOW, num, 1);
 	__recinfo_int(SESSION_QDEPTH, ri, r,
 		       session.queue_depth, IDBM_SHOW, num, 1);
+	__recinfo_int(SESSION_NR_SESSIONS, ri, r,
+		       session.nr_sessions, IDBM_SHOW, num, 1);
 	__recinfo_int_o2(SESSION_AUTH_METHOD, ri, r, session.auth.authmethod,
 			 IDBM_SHOW, "None", "CHAP", num, 1);
 	__recinfo_str(SESSION_USERNAME, ri, r,
@@ -369,6 +396,27 @@ void idbm_recinfo_iface(iface_rec_t *r, 
 	__recinfo_str(IFACE_TRANSPORTNAME, ri, r, transport_name,
 		      IDBM_SHOW, num, 1);
 	__recinfo_str(IFACE_INAME, ri, r, iname, IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_BOOT_PROTO, ri, r, bootproto, IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_SUBNET_MASK, ri, r, subnet_mask,
+		      IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_GATEWAY, ri, r, gateway, IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_IPV6_AUTOCFG, ri, r, ipv6_autocfg,
+		      IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_LINKLOCAL_AUTOCFG, ri, r, linklocal_autocfg,
+		      IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_ROUTER_AUTOCFG, ri, r, router_autocfg,
+		      IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_LINKLOCAL, ri, r, ipv6_linklocal,
+		      IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_ROUTER, ri, r, ipv6_router, IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_STATE, ri, r, state, IDBM_SHOW, num, 1);
+	__recinfo_uint16(IFACE_VLAN_ID, ri, r, vlan_id, IDBM_SHOW, num, 1);
+	__recinfo_uint8(IFACE_VLAN_PRIORITY, ri, r, vlan_priority,
+		      IDBM_SHOW, num, 1);
+	__recinfo_str(IFACE_VLAN_STATE, ri, r, vlan_state, IDBM_SHOW, num, 1);
+	__recinfo_int(IFACE_NUM, ri, r, iface_num, IDBM_SHOW, num, 1);
+	__recinfo_uint16(IFACE_MTU, ri, r, mtu, IDBM_SHOW, num, 1);
+	__recinfo_uint16(IFACE_PORT, ri, r, port, IDBM_SHOW, num, 1);
 }
 
 recinfo_t *idbm_recinfo_alloc(int max_keys)
@@ -426,6 +474,31 @@ void idbm_print(int type, void *rec, int
 }
 
 static void
+idbm_setup_session_defaults(struct iscsi_session_operational_config *conf)
+{
+	conf->InitialR2T = 0;
+	conf->ImmediateData = 1;
+	conf->FirstBurstLength = DEF_INI_FIRST_BURST_LEN;
+	conf->MaxBurstLength = DEF_INI_MAX_BURST_LEN;
+	conf->DefaultTime2Wait = ISCSI_DEF_TIME2WAIT;
+	conf->DefaultTime2Retain = 0;
+	conf->MaxConnections = 1;
+	conf->MaxOutstandingR2T = 1;
+	conf->ERL = 0;
+	conf->FastAbort = 1;
+}
+
+static void idbm_setup_conn_defaults(struct iscsi_conn_operational_config *conf)
+{
+	conf->MaxXmitDataSegmentLength = 0;
+	conf->MaxRecvDataSegmentLength = DEF_INI_MAX_RECV_SEG_LEN;
+	conf->HeaderDigest = CONFIG_DIGEST_NEVER;
+	conf->DataDigest = CONFIG_DIGEST_NEVER;
+	conf->IFMarker = 0;
+	conf->OFMarker = 0;
+}
+
+static void
 idbm_discovery_setup_defaults(discovery_rec_t *rec, discovery_type_e type)
 {
 	memset(rec, 0, sizeof(discovery_rec_t));
@@ -443,7 +516,10 @@ idbm_discovery_setup_defaults(discovery_
 		rec->u.sendtargets.conn_timeo.login_timeout=15;
 		rec->u.sendtargets.conn_timeo.auth_timeout = 45;
 		rec->u.sendtargets.conn_timeo.active_timeout=30;
-		rec->u.sendtargets.iscsi.MaxRecvDataSegmentLength =
+		idbm_setup_session_defaults(&rec->u.sendtargets.session_conf);
+		idbm_setup_conn_defaults(&rec->u.sendtargets.conn_conf);
+		/* override def setting */
+		rec->u.sendtargets.conn_conf.MaxRecvDataSegmentLength =
 						DEF_INI_DISC_MAX_RECV_SEG_LEN;
 		break;
 	case DISCOVERY_TYPE_SLP:
@@ -485,6 +561,20 @@ setup_passwd_len:
 				*(int*)info[i].data =
 					strtoul(value, NULL, 10);
 				goto updated;
+			} else if (info[i].type == TYPE_UINT8) {
+				if (!info[i].data)
+					continue;
+
+				*(uint8_t *)info[i].data =
+					strtoul(value, NULL, 10);
+				goto updated;
+			} else if (info[i].type == TYPE_UINT16) {
+				if (!info[i].data)
+					continue;
+
+				*(uint16_t *)info[i].data =
+					strtoul(value, NULL, 10);
+				goto updated;
 			} else if (info[i].type == TYPE_STR) {
 				if (!info[i].data)
 					continue;
@@ -515,7 +605,7 @@ setup_passwd_len:
 		}
 	}
 
-	return 1;
+	return ISCSI_ERR_INVAL;
 
 updated:
 	strlcpy((char*)info[i].value, value, VALUE_MAXVAL);
@@ -556,12 +646,12 @@ int idbm_verify_param(recinfo_t *info, c
 		else {
 			log_error("Cannot modify %s. It is used to look up "
 				  "the record and cannot be changed.", name);
-			return EINVAL;
+			return ISCSI_ERR_INVAL;
 		}
 	}
 
 	log_error("Cannot modify %s. Invalid param name.", name);
-	return EINVAL;
+	return ISCSI_ERR_INVAL;
 }
 
 void idbm_recinfo_config(recinfo_t *info, FILE *f)
@@ -627,7 +717,7 @@ void idbm_recinfo_config(recinfo_t *info
 		}
 		*(value+i) = 0;
 
-		(void)idbm_rec_update_param(info, name, value, line_number);
+		idbm_rec_update_param(info, name, value, line_number);
 	} while (line);
 }
 
@@ -781,19 +871,19 @@ get_params_from_disc_link(char *link, ch
 	(*target) = link;
 	*address = strchr(*target, ',');
 	if (!(*address))
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	*(*address)++ = '\0';
 	*port = strchr(*address, ',');
 	if (!(*port))
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	*(*port)++ = '\0';
 	*tpgt = strchr(*port, ',');
 	if (!(*tpgt))
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	*(*tpgt)++ = '\0';
 	*ifaceid = strchr(*tpgt, ',');
 	if (!(*ifaceid))
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	*(*ifaceid)++ = '\0';
 	return 0;
 }
@@ -809,8 +899,9 @@ int idbm_lock(void)
 
 	if (access(LOCK_DIR, F_OK) != 0) {
 		if (mkdir(LOCK_DIR, 0660) != 0) {
-			log_error("Could not open %s. Exiting\n", LOCK_DIR);
-			return errno;
+			log_error("Could not open %s: %s\n", LOCK_DIR,
+				  strerror(errno));
+			return ISCSI_ERR_IDBM;
 		}
 	}
 
@@ -827,7 +918,7 @@ int idbm_lock(void)
 			log_error("Maybe you are not root?");
 			log_error("Could not lock discovery DB: %s: %s",
 					LOCK_WRITE_FILE, strerror(errno));
-			return errno;
+			return ISCSI_ERR_IDBM;
 		} else if (i == 0)
 			log_debug(2, "Waiting for discovery DB lock");
 
@@ -880,7 +971,7 @@ static int __idbm_rec_read(node_rec_t *o
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	rc = idbm_lock();
 	if (rc)
@@ -888,8 +979,9 @@ static int __idbm_rec_read(node_rec_t *o
 
 	f = fopen(conf, "r");
 	if (!f) {
-		log_debug(5, "Could not open %s err %d\n", conf, errno);
-		rc = errno;
+		log_debug(5, "Could not open %s err %s\n", conf,
+			  strerror(errno));
+		rc = ISCSI_ERR_IDBM;
 		goto unlock;
 	}
 
@@ -916,7 +1008,7 @@ idbm_rec_read(node_rec_t *out_rec, char 
 
 	portal = calloc(1, PATH_MAX);
 	if (!portal)
-		return ENOMEM;
+		return ISCSI_ERR_IDBM;
 
 	/* try old style portal as config */
 	snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
@@ -929,14 +1021,14 @@ idbm_rec_read(node_rec_t *out_rec, char 
 		 targetname, ip, port, tpgt, iface->name);
 	log_debug(5, "rec read looking for config file %s.", portal);
 	if (!strlen(iface->name)) {
-		rc = EINVAL;
+		rc = ISCSI_ERR_INVAL;
 		goto free_portal;
 	}
 
 	if (stat(portal, &statb)) {
-		log_debug(5, "Could not stat %s err %d.", portal, errno);
+		log_debug(5, "Could not stat %s: %s.", portal, strerror(errno));
 		free(portal);
-		return errno;
+		return ISCSI_ERR_IDBM;
 	}
 
 read:
@@ -1073,22 +1165,16 @@ int idbm_for_each_isns_drec(void *data, 
 static int __idbm_print_all_by_drec(void *data, struct discovery_rec *drec)
 {
 	int info_level = *(int *)data;
-	int rc;
 
 	if (info_level >= 1) {
 		printf("DiscoveryAddress: %s,%d\n",
 		       drec->address, drec->port);
-		rc = idbm_print_discovered(drec, info_level);
-		if (rc)
-			return 0;
-		else
-			return ENODEV;
-	} else {
+		idbm_print_discovered(drec, info_level);
+	} else
 		printf("%s:%d via %s\n", drec->address, drec->port,
 		       drec->type == DISCOVERY_TYPE_ISNS ?
 		       "isns" : "sendtargets");
-		return 0;
-	}
+	return 0;
 }
 
 static int idbm_print_all_st(int info_level)
@@ -1168,11 +1254,23 @@ int idbm_print_all_discovery(int info_le
 	return found;
 }
 
-/*
- * This iterates over the ifaces in use in the nodes dir.
- * It does not iterate over the ifaces setup in /etc/iscsi/ifaces.
+/**
+ * idbm_for_each_iface - iterate over bound iface recs
+ * @found: nr of recs found so far
+ * @data: data pointer passed to fn
+ * @fn: iterator function ran over each bound iface rec
+ * @targetname: rec's target name
+ * @tpgt: rec's portal group tag
+ * @ip: rec's ip address
+ * @port: rec's port
+ *
+ * This will run fn over all recs with the {targetname,tpgt,ip,port}
+ * id. It does not iterate over the ifaces setup in /etc/iscsi/ifaces.
+ *
+ * fn should return -1 if it skipped the rec, a ISCSI_ERR error code if
+ * the operation failed or 0 if fn was run successfully.
  */
-int idbm_for_each_iface(int *found, void *data,
+static int idbm_for_each_iface(int *found, void *data,
 				idbm_iface_op_fn *fn,
 				char *targetname, int tpgt, char *ip, int port)
 {
@@ -1185,7 +1283,7 @@ int idbm_for_each_iface(int *found, void
 
 	portal = calloc(1, PATH_MAX);
 	if (!portal)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	if (tpgt >= 0)
 		goto read_iface;
@@ -1195,7 +1293,7 @@ int idbm_for_each_iface(int *found, void
 		 ip, port);
 	if (stat(portal, &statb)) {
 		log_error("iface iter could not stat %s.", portal);
-		rc = ENODEV;
+		rc = ISCSI_ERR_IDBM;
 		goto free_portal;
 	}
 
@@ -1217,11 +1315,13 @@ read_iface:
 	iface_dirfd = opendir(portal);
 	if (!iface_dirfd) {
 		log_error("iface iter could not read dir %s.", portal);
-		rc = errno;
+		rc = ISCSI_ERR_IDBM;
 		goto free_portal;
 	}
 
 	while ((iface_dent = readdir(iface_dirfd))) {
+		int curr_rc;
+
 		if (!strcmp(iface_dent->d_name, ".") ||
 		    !strcmp(iface_dent->d_name, ".."))
 			continue;
@@ -1233,14 +1333,12 @@ read_iface:
 		if (__idbm_rec_read(&rec, portal))
 			continue;
 
+		curr_rc = fn(data, &rec);
 		/* less than zero means it was not a match */
-		rc = fn(data, &rec);
-		if (rc > 0)
-			break;
-		else if (rc == 0)
+		if (curr_rc > 0 && !rc)
+			rc = curr_rc;
+		else if (curr_rc == 0)
 			(*found)++;
-		else 
-			rc = 0;
 	}
 
 	closedir(iface_dirfd);
@@ -1263,17 +1361,18 @@ int idbm_for_each_portal(int *found, voi
 
 	portal = calloc(1, PATH_MAX);
 	if (!portal)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, targetname);
 	portal_dirfd = opendir(portal);
 	if (!portal_dirfd) {
-		rc = errno;
+		rc = ISCSI_ERR_IDBM;
 		goto done;
 	}
 
 	while ((portal_dent = readdir(portal_dirfd))) {
 		char *tmp_port, *tmp_tpgt;
+		int curr_rc;
 
 		if (!strcmp(portal_dent->d_name, ".") ||
 		    !strcmp(portal_dent->d_name, ".."))
@@ -1288,11 +1387,12 @@ int idbm_for_each_portal(int *found, voi
 		if (tmp_tpgt)
 			*tmp_tpgt++ = '\0';
 
-		rc = fn(found, data, targetname,
+		curr_rc = fn(found, data, targetname,
 			tmp_tpgt ? atoi(tmp_tpgt) : -1,
 			portal_dent->d_name, atoi(tmp_port));
-		if (rc)
-			break;
+		/* less than zero means it was not a match */
+		if (curr_rc > 0 && !rc)
+			rc = curr_rc;
 	}
 	closedir(portal_dirfd);
 done:
@@ -1314,14 +1414,17 @@ int idbm_for_each_node(int *found, void 
 		return 0;
 
 	while ((node_dent = readdir(node_dirfd))) {
+		int curr_rc;
+
 		if (!strcmp(node_dent->d_name, ".") ||
 		    !strcmp(node_dent->d_name, ".."))
 			continue;
 
 		log_debug(5, "searching %s\n", node_dent->d_name);
-		rc = fn(found, data, node_dent->d_name);
-		if (rc)
-			break;
+		curr_rc = fn(found, data, node_dent->d_name);
+		/* less than zero means it was not a match */
+		if (curr_rc > 0 && !rc)
+			rc = curr_rc;
 	}
 
 	closedir(node_dirfd);
@@ -1376,17 +1479,17 @@ idbm_discovery_read(discovery_rec_t *out
 	FILE *f;
 
 	if (drec_type > 1)
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 
 	memset(out_rec, 0, sizeof(discovery_rec_t));
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	portal = malloc(PATH_MAX);
 	if (!portal) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_info;
 	}
 
@@ -1402,8 +1505,9 @@ idbm_discovery_read(discovery_rec_t *out
 	f = idbm_open_rec_r(portal,
 			    disc_type_to_config_vals[drec_type].config_name);
 	if (!f) {
-		log_debug(1, "Could not open %s err %d\n", portal, errno);
-		rc = errno;
+		log_debug(1, "Could not open %s: %s\n", portal,
+			  strerror(errno));
+		rc = ISCSI_ERR_IDBM;
 		goto unlock;
 	}
 
@@ -1474,14 +1578,15 @@ static int idbm_rec_write(node_rec_t *re
 	portal = malloc(PATH_MAX);
 	if (!portal) {
 		log_error("Could not alloc portal\n");
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	}
 
 	snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
 	if (access(portal, F_OK) != 0) {
 		if (mkdir(portal, 0660) != 0) {
-			log_error("Could not make %s\n", portal);
-			rc = errno;
+			log_error("Could not make %s: %s\n", portal,
+				  strerror(errno));
+			rc = ISCSI_ERR_IDBM;
 			goto free_portal;
 		}
 	}
@@ -1489,8 +1594,9 @@ static int idbm_rec_write(node_rec_t *re
 	snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
 	if (access(portal, F_OK) != 0) {
 		if (mkdir(portal, 0660) != 0) {
-			log_error("Could not make %s\n", portal);
-			rc = errno;
+			log_error("Could not make %s: %s\n", portal,
+				  strerror(errno));
+			rc = ISCSI_ERR_IDBM;
 			goto free_portal;
 		}
 	}
@@ -1531,13 +1637,13 @@ static int idbm_rec_write(node_rec_t *re
 		 * Old style portal as a file, but with tpgt. Let's update it.
 		 */
 		if (unlink(portal)) {
-			log_error("Could not convert %s. err %d\n", portal,
-				  errno);
-			rc = errno;
+			log_error("Could not convert %s: %s\n", portal,
+				  strerror(errno));
+			rc = ISCSI_ERR_IDBM;
 			goto unlock;
 		}
 	} else {
-		rc = EINVAL;
+		rc = ISCSI_ERR_INVAL;
 		goto unlock;
 	}	
 
@@ -1546,9 +1652,9 @@ mkdir_portal:
 		 rec->name, rec->conn[0].address, rec->conn[0].port, rec->tpgt);
 	if (stat(portal, &statb)) {
 		if (mkdir(portal, 0660) != 0) {
-			log_error("Could not make dir %s err %d\n",
-				  portal, errno);
-			rc = errno;
+			log_error("Could not make dir %s: %s\n",
+				  portal, strerror(errno));
+			rc = ISCSI_ERR_IDBM;
 			goto unlock;
 		}
 	}
@@ -1559,8 +1665,8 @@ mkdir_portal:
 open_conf:
 	f = fopen(portal, "w");
 	if (!f) {
-		log_error("Could not open %s err %d\n", portal, errno);
-		rc = errno;
+		log_error("Could not open %s: %sd\n", portal, strerror(errno));
+		rc = ISCSI_ERR_IDBM;
 		goto unlock;
 	}
 
@@ -1581,12 +1687,12 @@ idbm_discovery_write(discovery_rec_t *re
 	int rc = 0;
 
 	if (rec->type > 1)
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 
 	portal = malloc(PATH_MAX);
 	if (!portal) {
 		log_error("Could not alloc portal\n");
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	}
 
 	rc = idbm_lock();
@@ -1597,8 +1703,9 @@ idbm_discovery_write(discovery_rec_t *re
 		 disc_type_to_config_vals[rec->type].config_root);
 	if (access(portal, F_OK) != 0) {
 		if (mkdir(portal, 0660) != 0) {
-			log_error("Could not make %s\n", portal);
-			rc = errno;
+			log_error("Could not make %s: %s\n", portal,
+				  strerror(errno));
+			rc = ISCSI_ERR_IDBM;
 			goto unlock;
 		}
 	}
@@ -1610,8 +1717,8 @@ idbm_discovery_write(discovery_rec_t *re
 	f = idbm_open_rec_w(portal,
 			    disc_type_to_config_vals[rec->type].config_name);
 	if (!f) {
-		log_error("Could not open %s err %d\n", portal, errno);
-		rc = errno;
+		log_error("Could not open %s: %s\n", portal, strerror(errno));
+		rc = ISCSI_ERR_IDBM;
 		goto unlock;
 	}
 
@@ -1655,9 +1762,9 @@ static int setup_disc_to_node_link(char 
 	case DISCOVERY_TYPE_FW:
 		if (access(FW_CONFIG_DIR, F_OK) != 0) {
 			if (mkdir(FW_CONFIG_DIR, 0660) != 0) {
-				log_error("Could not make %s\n",
-					  FW_CONFIG_DIR);
-				rc = errno;
+				log_error("Could not make %s: %s",
+					  FW_CONFIG_DIR, strerror(errno));
+				rc = ISCSI_ERR_IDBM;
 			}
 		}
 
@@ -1669,9 +1776,9 @@ static int setup_disc_to_node_link(char 
 	case DISCOVERY_TYPE_STATIC:
 		if (access(STATIC_CONFIG_DIR, F_OK) != 0) {
 			if (mkdir(STATIC_CONFIG_DIR, 0660) != 0) {
-				log_error("Could not make %s\n",
-					  STATIC_CONFIG_DIR);
-				rc = errno;
+				log_error("Could not make %s; %s",
+					  STATIC_CONFIG_DIR, strerror(errno));
+				rc = ISCSI_ERR_IDBM;
 			}
 		}
 
@@ -1683,9 +1790,9 @@ static int setup_disc_to_node_link(char 
 	case DISCOVERY_TYPE_ISNS:
 		if (access(ISNS_CONFIG_DIR, F_OK) != 0) {
 			if (mkdir(ISNS_CONFIG_DIR, 0660) != 0) {
-				log_error("Could not make %s\n",
-					  ISNS_CONFIG_DIR);
-				rc = errno;
+				log_error("Could not make %s: %s",
+					  ISNS_CONFIG_DIR, strerror(errno));
+				rc = ISCSI_ERR_IDBM;
 			}
 		}
 
@@ -1732,7 +1839,7 @@ static int setup_disc_to_node_link(char 
 		break;
 	case DISCOVERY_TYPE_SLP:
 	default:
-		rc = EINVAL;
+		rc = ISCSI_ERR_INVAL;
 	}
 
 	return rc;
@@ -1773,7 +1880,7 @@ int idbm_add_node(node_rec_t *newrec, di
 
 	node_portal = calloc(2, PATH_MAX);
 	if (!node_portal)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	disc_portal = node_portal + PATH_MAX;
 	snprintf(node_portal, PATH_MAX, "%s/%s/%s,%d,%d", NODE_CONFIG_DIR,
@@ -1795,9 +1902,10 @@ int idbm_add_node(node_rec_t *newrec, di
 			log_debug(7, "link from %s to %s exists", node_portal,
 				  disc_portal);
 		else {
-			rc = errno;
+			rc = ISCSI_ERR_IDBM;
 			log_error("Could not make link from disc source %s to "
-				 "node %s", disc_portal, node_portal);
+				 "node %s: %s", disc_portal, node_portal,
+				 strerror(errno));
 		}
 	}
 	idbm_unlock();
@@ -1812,10 +1920,12 @@ static int idbm_bind_iface_to_nodes(idbm
 {
 	struct node_rec *rec, *tmp;
 	struct list_head new_recs;
+	int rc;
 
 	INIT_LIST_HEAD(&new_recs);
-	if (disc_node_fn(data, iface, &new_recs))
-		return ENODEV;
+	rc = disc_node_fn(data, iface, &new_recs);
+	if (rc)
+		return rc;
 
 	list_for_each_entry_safe(rec, tmp, &new_recs, list) {
 		list_del_init(&rec->list);
@@ -1825,6 +1935,20 @@ static int idbm_bind_iface_to_nodes(idbm
 	return 0;
 }
 
+static int
+discovery_error_fatal(int err)
+{
+	switch (err) {
+	/* No error */
+	case ISCSI_SUCCESS:
+	/* Transport errors or timeouts are not fatal */
+	case ISCSI_ERR_TRANS:
+	case ISCSI_ERR_TRANS_TIMEOUT:
+		return 0;
+	}
+	return 1;
+}
+
 int idbm_bind_ifaces_to_nodes(idbm_disc_nodes_fn *disc_node_fn,
 			      void *data, struct list_head *ifaces,
 			      struct list_head *bound_recs)
@@ -1856,7 +1980,7 @@ int idbm_bind_ifaces_to_nodes(idbm_disc_
 			rc = idbm_bind_iface_to_nodes(disc_node_fn, data, iface,
 						      bound_recs);
 			free(iface);
-			if (rc)
+			if (discovery_error_fatal(rc))
 				goto fail;
 			found = 1;
 		}
@@ -1883,7 +2007,7 @@ int idbm_bind_ifaces_to_nodes(idbm_disc_
 
 			rc = idbm_bind_iface_to_nodes(disc_node_fn, data, iface,
 						      bound_recs);
-			if (rc)
+			if (discovery_error_fatal(rc))
 				goto fail;
 		}
 	}
@@ -1960,7 +2084,7 @@ int idbm_delete_discovery(discovery_rec_
 
 	portal = calloc(1, PATH_MAX);
 	if (!portal)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	snprintf(portal, PATH_MAX, "%s/%s,%d",
 		 disc_type_to_config_vals[drec->type].config_root,
@@ -2017,7 +2141,7 @@ static int idbm_remove_disc_to_node_link
 
 	tmprec = malloc(sizeof(*tmprec));
 	if (!tmprec)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	memset(portal, 0, PATH_MAX);
 	snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%d/%s", NODE_CONFIG_DIR,
@@ -2045,9 +2169,9 @@ static int idbm_remove_disc_to_node_link
 
 	if (!stat(portal, &statb)) {
 		if (unlink(portal)) {
-			log_error("Could not remove link %s err %d\n",
-				  portal, errno);
-			rc = errno;
+			log_error("Could not remove link %s: %s\n",
+				  portal, strerror(errno));
+			rc = ISCSI_ERR_IDBM;
 		} else
 			log_debug(7, "rmd %s", portal);
 	} else
@@ -2073,7 +2197,7 @@ int idbm_delete_node(node_rec_t *rec)
 
 	portal = calloc(1, PATH_MAX);
 	if (!portal)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	rc = idbm_remove_disc_to_node_link(rec, portal);
 	if (rc)
@@ -2100,15 +2224,15 @@ int idbm_delete_node(node_rec_t *rec)
 	if (!stat(portal, &statb))
 		goto rm_conf;
 
-	log_error("Could not stat %s to delete node err %d\n",
-		  portal, errno);
-	rc = errno;
+	log_error("Could not stat %s to delete node: %s\n",
+		  portal, strerror(errno));
+	rc = ISCSI_ERR_IDBM;
 	goto unlock;
 
 rm_conf:
 	if (unlink(portal)) {
-		log_error("Could not remove %s err %d\n", portal, errno);
-		rc = errno;
+		log_error("Could not remove %s: %s\n", portal, strerror(errno));
+		rc = ISCSI_ERR_IDBM;
 		goto unlock;
 	}
 
@@ -2178,7 +2302,7 @@ int idbm_node_set_param(void *data, node
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	idbm_recinfo_node(rec, info);
 
@@ -2207,7 +2331,7 @@ int idbm_discovery_set_param(void *data,
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	idbm_recinfo_discovery((discovery_rec_t *)rec, info);
 
@@ -2242,7 +2366,7 @@ int idbm_init(idbm_get_config_file_fn *f
 	db = malloc(sizeof(idbm_t));
 	if (!db) {
 		log_error("out of memory on idbm allocation");
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	}
 	memset(db, 0, sizeof(idbm_t));
 	db->get_config_file = fn;
@@ -2348,10 +2472,12 @@ void idbm_node_setup_defaults(node_rec_t
 
 	rec->tpgt = PORTAL_GROUP_TAG_UNKNOWN;
 	rec->disc_type = DISCOVERY_TYPE_STATIC;
+	rec->leading_login = 0;
 	rec->session.cmds_max = CMDS_MAX;
 	rec->session.xmit_thread_priority = XMIT_THREAD_PRIORITY;
 	rec->session.initial_cmdsn = 0;
 	rec->session.queue_depth = QUEUE_DEPTH;
+	rec->session.nr_sessions = 1;
 	rec->session.initial_login_retry_max = DEF_INITIAL_LOGIN_RETRIES_MAX;
 	rec->session.reopen_max = 32;
 	rec->session.auth.authmethod = 0;
@@ -2362,16 +2488,10 @@ void idbm_node_setup_defaults(node_rec_t
 	rec->session.err_timeo.tgt_reset_timeout = DEF_TGT_RESET_TIMEO;
 	rec->session.err_timeo.host_reset_timeout = DEF_HOST_RESET_TIMEO;
 	rec->session.timeo.replacement_timeout = DEF_REPLACEMENT_TIMEO;
-	rec->session.iscsi.InitialR2T = 0;
-	rec->session.iscsi.ImmediateData = 1;
-	rec->session.iscsi.FirstBurstLength = DEF_INI_FIRST_BURST_LEN;
-	rec->session.iscsi.MaxBurstLength = DEF_INI_MAX_BURST_LEN;
-	rec->session.iscsi.DefaultTime2Wait = ISCSI_DEF_TIME2WAIT;
-	rec->session.iscsi.DefaultTime2Retain = 0;
-	rec->session.iscsi.MaxConnections = 1;
-	rec->session.iscsi.MaxOutstandingR2T = 1;
-	rec->session.iscsi.ERL = 0;
-	rec->session.iscsi.FastAbort = 1;
+	rec->session.info = NULL;
+	rec->session.sid = 0;
+	rec->session.multiple = 0;
+	idbm_setup_session_defaults(&rec->session.iscsi);
 
 	for (i=0; i<ISCSI_CONN_MAX; i++) {
 		rec->conn[i].startup = ISCSI_STARTUP_MANUAL;
@@ -2385,13 +2505,7 @@ void idbm_node_setup_defaults(node_rec_t
 		rec->conn[i].timeo.noop_out_interval = DEF_NOOP_OUT_INTERVAL;
 		rec->conn[i].timeo.noop_out_timeout = DEF_NOOP_OUT_TIMEO;
 
-		rec->conn[i].iscsi.MaxXmitDataSegmentLength = 0;
-		rec->conn[i].iscsi.MaxRecvDataSegmentLength =
-						DEF_INI_MAX_RECV_SEG_LEN;
-		rec->conn[i].iscsi.HeaderDigest = CONFIG_DIGEST_NEVER;
-		rec->conn[i].iscsi.DataDigest = CONFIG_DIGEST_NEVER;
-		rec->conn[i].iscsi.IFMarker = 0;
-		rec->conn[i].iscsi.OFMarker = 0;
+		idbm_setup_conn_defaults(&rec->conn[i].iscsi);
 	}
 
 	iface_setup_defaults(&rec->iface);
@@ -2404,7 +2518,8 @@ idbm_find_rec_in_list(struct list_head *
 	struct node_rec *rec;
 
 	list_for_each_entry(rec, rec_list, list) {
-		if (__iscsi_match_session(rec, targetname, addr, port, iface))
+		if (__iscsi_match_session(rec, targetname, addr, port, iface,
+					  MATCH_ANY_SID))
 			return rec;
 	}
 
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/idbm_fields.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/idbm_fields.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/idbm_fields.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/idbm_fields.h	2011-08-14 16:48:25.000000000 -0500
@@ -10,6 +10,7 @@
 #define NODE_NAME	"node.name"
 #define NODE_TPGT	"node.tpgt"
 #define NODE_STARTUP	"node.startup"
+#define NODE_LEADING_LOGIN "node.leading_login"
 #define NODE_DISC_ADDR	"node.discovery_address"
 #define NODE_DISC_PORT	"node.discovery_port"
 #define NODE_DISC_TYPE	"node.discovery_type"
@@ -21,6 +22,7 @@
 #define SESSION_CMDS_MAX	"node.session.cmds_max"
 #define SESSION_XMIT_THREAD_PRIORITY "node.session.xmit_thread_priority"
 #define SESSION_QDEPTH		"node.session.queue_depth"
+#define SESSION_NR_SESSIONS	"node.session.nr_sessions"
 #define SESSION_AUTH_METHOD	"node.session.auth.authmethod"
 #define SESSION_USERNAME	"node.session.auth.username"
 #define SESSION_PASSWORD	"node.session.auth.password"
@@ -75,7 +77,18 @@
 #define IFACE_GATEWAY		"iface.gateway"
 #define IFACE_PRIMARY_DNS	"iface.primary_dns"
 #define IFACE_SEC_DNS		"iface.secondary_dns"
-#define IFACE_VLAN		"iface.vlan"
+#define IFACE_VLAN_ID		"iface.vlan_id"
+#define IFACE_VLAN_PRIORITY	"iface.vlan_priority"
+#define IFACE_VLAN_STATE	"iface.vlan_state"
+#define IFACE_LINKLOCAL	"iface.ipv6_linklocal"
+#define IFACE_ROUTER		"iface.ipv6_router"
+#define IFACE_IPV6_AUTOCFG	"iface.ipv6_autocfg"
+#define IFACE_LINKLOCAL_AUTOCFG	"iface.linklocal_autocfg"
+#define IFACE_ROUTER_AUTOCFG	"iface.router_autocfg"
+#define IFACE_STATE		"iface.state"
+#define IFACE_NUM		"iface.iface_num"
+#define IFACE_MTU		"iface.mtu"
+#define IFACE_PORT		"iface.port"
 
 /* discovery fields */
 #define DISC_STARTUP		"discovery.startup"
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/idbm.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/idbm.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/idbm.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/idbm.h	2011-08-14 16:48:25.000000000 -0500
@@ -39,6 +39,8 @@
 #define TYPE_INT	0
 #define TYPE_INT_O	1
 #define TYPE_STR	2
+#define TYPE_UINT8	3
+#define TYPE_UINT16	4
 #define MAX_KEYS	256   /* number of keys total(including CNX_MAX) */
 #define NAME_MAXVAL	128   /* the maximum length of key name */
 #define VALUE_MAXVAL	256   /* the maximum length of 223 bytes in the RFC. */
@@ -93,9 +95,6 @@ struct rec_op_data {
 	node_rec_t *match_rec;
 	idbm_iface_op_fn *fn;
 };
-extern int idbm_for_each_iface(int *found, void *data,
-				idbm_iface_op_fn *fn,
-				char *targetname, int tpgt, char *ip, int port);
 extern int idbm_for_each_portal(int *found, void *data,
 				idbm_portal_op_fn *fn, char *targetname);
 extern int idbm_for_each_node(int *found, void *data,
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iface.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iface.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iface.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iface.c	2011-08-14 16:48:25.000000000 -0500
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <arpa/inet.h>
 
 #include "log.h"
 #include "list.h"
@@ -39,6 +40,7 @@
 #include "host.h"
 #include "fw_context.h"
 #include "sysdeps.h"
+#include "iscsi_err.h"
 
 /*
  * Default ifaces for use with transports that do not bind to hardware
@@ -101,13 +103,13 @@ struct iface_rec *iface_alloc(char *ifna
 	struct iface_rec *iface;
 
 	if (!strlen(ifname) || strlen(ifname) + 1 > ISCSI_MAX_IFACE_LEN) {
-		*err = EINVAL;
+		*err = ISCSI_ERR_INVAL;
 		return NULL;
 	}
 
 	iface = calloc(1, sizeof(*iface));
 	if (!iface) {
-		*err = ENOMEM;
+		*err = ISCSI_ERR_NOMEM;
 		return NULL;
 	}
 
@@ -125,11 +127,11 @@ static int __iface_conf_read(struct ifac
 
 	iface_conf = calloc(1, PATH_MAX);
 	if (!iface_conf)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
 	if (!info) {
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_conf;
 	}
 
@@ -147,7 +149,7 @@ static int __iface_conf_read(struct ifac
 			iface_setup_defaults(iface);
 			rc = 0;
 		} else
-			rc = errno;
+			rc = ISCSI_ERR_IDBM;
 		goto free_info;
 	}
 
@@ -213,12 +215,12 @@ int iface_conf_delete(struct iface_rec *
 	if (def_iface) {
 		log_error("iface %s is a special interface and "
 			  "cannot be deleted.\n", iface->name);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	iface_conf = calloc(1, PATH_MAX);
 	if (!iface_conf)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name);
 	rc = idbm_lock();
@@ -226,7 +228,7 @@ int iface_conf_delete(struct iface_rec *
 		goto free_conf;
 
 	if (unlink(iface_conf))
-		rc = errno;
+		rc = ISCSI_ERR_IDBM;
 	idbm_unlock();
 
 free_conf:
@@ -246,17 +248,17 @@ int iface_conf_write(struct iface_rec *i
 		log_error("iface %s is a special interface and "
 			  "is not stored in %s.\n", iface->name,
 			  IFACE_CONFIG_DIR);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	iface_conf = calloc(1, PATH_MAX);
 	if (!iface_conf)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name);
 	f = fopen(iface_conf, "w");
 	if (!f) {
-		rc = errno;
+		rc = ISCSI_ERR_IDBM;
 		goto free_conf;
 	}
 
@@ -285,12 +287,12 @@ int iface_conf_update(struct db_set_para
 	if (def_iface) {
 		log_error("iface %s is a special interface and "
 			  "cannot be modified.\n", iface->name);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	idbm_recinfo_iface(iface, info);
 	rc = idbm_verify_param(info, param->name);
@@ -298,10 +300,8 @@ int iface_conf_update(struct db_set_para
 		goto free_info;
 
 	rc = idbm_rec_update_param(info, param->name, param->value, 0);
-	if (rc) {
-		rc = EIO;
+	if (rc)
 		goto free_info;
-	}
 
 	rc = iface_conf_write(iface);
 free_info:
@@ -309,6 +309,7 @@ free_info:
 	return rc;
 }
 
+#if 0 /* Unused */
 static int iface_get_next_id(void)
 {
 	struct stat statb;
@@ -346,6 +347,7 @@ static int iface_get_next_id(void)
 	free(iface_conf);
         return rc;
 }
+#endif /* Unused */
 
 struct iface_search {
 	struct iface_rec *pattern;
@@ -362,7 +364,8 @@ static int __iface_get_by_net_binding(vo
 	}
 
 	if (iface_is_bound_by_hwaddr(search->pattern)) {
-		if (!strcmp(iface->hwaddress, search->pattern->hwaddress)) {
+		if (!strcasecmp(iface->hwaddress,
+				search->pattern->hwaddress)) {
 			iface_copy(search->found, iface);
 			return 1;
 		} else
@@ -418,7 +421,7 @@ int iface_get_by_net_binding(struct ifac
 				  __iface_get_by_net_binding);
 	if (rc == 1)
 		return 0;
-	return ENODEV;
+	return ISCSI_ERR_NO_OBJS_FOUND;
 }
 
 static int __iface_setup_host_bindings(void *data, struct host_info *hinfo)
@@ -438,7 +441,8 @@ static int __iface_setup_host_bindings(v
 			return 0;
 	}
 
-	if (iface_get_by_net_binding(&hinfo->iface, &iface) == ENODEV) {
+	if (iface_get_by_net_binding(&hinfo->iface, &iface) ==
+	    ISCSI_ERR_NO_OBJS_FOUND) {
 		/* Must be a new port */
 		if (!strlen(hinfo->iface.hwaddress)) {
 			log_error("Invalid offload iSCSI host %u. Missing "
@@ -704,7 +708,7 @@ int iface_for_each_iface(void *data, int
 			 iface_dent->d_name);
 		iface = iface_alloc(iface_dent->d_name, &err);
 		if (!iface || err) {
-			if (err == EINVAL)
+			if (err == ISCSI_ERR_INVAL)
 				log_error("Invalid iface name %s. Must be "
 					  "from 1 to %d characters.",
 					   iface_dent->d_name,
@@ -756,7 +760,7 @@ static int iface_link(void *data, struct
 
 	iface_copy = calloc(1, sizeof(*iface_copy));
 	if (!iface_copy)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	memcpy(iface_copy, iface, sizeof(*iface_copy));
 	INIT_LIST_HEAD(&iface_copy->list);
@@ -788,42 +792,54 @@ void iface_link_ifaces(struct list_head 
 int iface_setup_from_boot_context(struct iface_rec *iface,
 				   struct boot_context *context)
 {
+	struct iscsi_transport *t;
+	uint32_t hostno;
+
 	if (strlen(context->initiatorname))
 		strlcpy(iface->iname, context->initiatorname,
 			sizeof(iface->iname));
 
 	if (strlen(context->scsi_host_name)) {
-		struct iscsi_transport *t;
-		uint32_t hostno;
-
 		if (sscanf(context->scsi_host_name, "iscsi_boot%u", &hostno) != 		    1) {
 			log_error("Could not parse %s's host no.",
 				  context->scsi_host_name);
 			return 0;
 		}
-		t = iscsi_sysfs_get_transport_by_hba(hostno);
-		if (!t) {
-			log_error("Could not get transport for %s. "
-				  "Make sure the iSCSI driver is loaded.",
-				  context->scsi_host_name);
+	} else if (strlen(context->iface)) {
+/* this ifdef is only temp until distros and firmwares are updated */
+#ifdef OFFLOAD_BOOT_SUPPORTED
+		hostno = iscsi_sysfs_get_host_no_from_hwaddress(context->mac,
+								&rc);
+		if (rc) {
+			/*
+			 * If the MAC in the boot info does not match a iscsi
+			 * host then the MAC must be for network card, so boot
+			 * is not going to be offloaded.
+			 */
+			log_debug(3, "Could not match %s to host\n",
+				  context->mac);
 			return 0;
 		}
 
-		log_debug(3, "boot context has %s transport %s",
-			  context->scsi_host_name, t->name);
-		strcpy(iface->transport_name, t->name);
-	} else if (strlen(context->iface) &&
-		 (!net_get_transport_name_from_netdev(context->iface,
-						iface->transport_name))) {
-		log_debug(3, "boot context has netdev %s",
-			  context->iface);
-		strlcpy(iface->netdev, context->iface,
-			sizeof(iface->netdev));
+		strlcpy(iface->netdev, context->iface, sizeof(iface->netdev));
+#else
+		return 0;
+#endif
 	} else
 		return 0;
+
 	/*
 	 * set up for access through a offload card.
 	 */
+	t = iscsi_sysfs_get_transport_by_hba(hostno);
+	if (!t) {
+		log_error("Could not get transport for host%u. "
+			  "Make sure the iSCSI driver is loaded.",
+			  hostno);
+		return 0;
+	}
+	strcpy(iface->transport_name, t->name);
+
 	memset(iface->name, 0, sizeof(iface->name));
 	snprintf(iface->name, sizeof(iface->name), "%s.%s",
 		 iface->transport_name, context->mac);
@@ -885,3 +901,821 @@ fail:
 	}
 	return rc;
 }
+
+struct iface_param_count {
+	struct iface_rec *primary;
+	int count;
+};
+
+/**
+ * __iface_get_param_count - Gets netconfig parameter count for given iface
+ * @data: iface_param_count structure
+ * @iface: iface to setup
+ */
+static int __iface_get_param_count(void *data, struct iface_rec *iface)
+{
+	struct iface_param_count *iface_params = data;
+	int iptype = ISCSI_IFACE_TYPE_IPV4;
+	int count = 0;
+
+	if (strcmp(iface_params->primary->hwaddress, iface->hwaddress))
+		return 0;
+
+	if (strcmp(iface->bootproto, "dhcp") && !strstr(iface->ipaddress, "."))
+		iptype = ISCSI_IFACE_TYPE_IPV6;
+
+	if (iptype == ISCSI_IFACE_TYPE_IPV4) {
+
+		if (strcmp(iface->state, "disable")) {
+			if (strstr(iface->bootproto, "dhcp"))
+				/* DHCP enabled */
+				count++;
+			else {
+				/* DHCP disabled */
+				count++;
+
+				if (strstr(iface->ipaddress, ".")) {
+					/* User configured IPv4 Address */
+					count++;
+
+					if (strstr(iface->subnet_mask, "."))
+						/* User configured Subnet */
+						count++;
+
+					if (strstr(iface->gateway, "."))
+						/* User configured Gateway */
+						count++;
+				} else
+					/*
+					 * IPv4 Address not valid, decrement
+					 * count of DHCP
+					 */
+					count--;
+			}
+
+			/*
+			 * If IPv4 configuration in iface file is valid,
+			 * enable state and other parameters (if any)
+			 */
+			if (count) {
+				/* iface state */
+				count++;
+
+				if (strcmp(iface->vlan_state, "disable")) {
+					/* vlan_state enabled */
+					count++;
+
+					if (iface->vlan_id)
+						/* For vlan value */
+						count++;
+				} else
+					/* vlan_state disabled */
+					count++;
+
+				if (iface->mtu)
+					count++;
+
+				if (iface->port)
+					count++;
+			}
+		} else
+			/* IPv4 is disabled, iface state */
+			count++;
+
+	} else if (iptype == ISCSI_IFACE_TYPE_IPV6) {
+
+		if (strcmp(iface->state, "disable")) {
+
+			/* IPv6 Address */
+			if (strstr(iface->ipv6_autocfg, "nd") ||
+			    strstr(iface->ipv6_autocfg, "dhcpv6"))
+				/* Autocfg enabled */
+				count++;
+			else {
+				/* Autocfg disabled */
+				count++;
+
+				if (strstr(iface->ipaddress, ":"))
+					/* User configured IPv6 Address */
+					count++;
+				else
+					/*
+					 * IPv6 Address not valid, decrement
+					 * count of IPv6 Autocfg
+					 */
+					count--;
+			}
+
+			/* IPv6 LinkLocal Address */
+			if (strstr(iface->linklocal_autocfg, "auto"))
+				/* Autocfg enabled */
+				count++;
+			else {
+				/* Autocfg disabled */
+				count++;
+
+				if (strstr(iface->ipv6_linklocal, ":"))
+					/* User configured LinkLocal Address */
+					count++;
+				else
+					/*
+					 * LinkLocal Address not valid,
+					 * decrement count of LinkLocal Autocfg
+					 */
+					count--;
+			}
+
+			/* IPv6 Router Address */
+			if (strstr(iface->router_autocfg, "auto"))
+				/* Autocfg enabled */
+				count++;
+			else {
+				/* Autocfg disabled */
+				count++;
+
+				if (strstr(iface->ipv6_router, ":"))
+					/* User configured Router Address */
+					count++;
+				else
+					/*
+					 * Router Address not valid,
+					 * decrement count of Router Autocfg
+					 */
+					count--;
+			}
+
+			/*
+			 * If IPv6 configuration in iface file is valid,
+			 * enable state and other parameters (if any)
+			 */
+			if (count) {
+				/* iface state */
+				count++;
+
+				if (strcmp(iface->vlan_state, "disable")) {
+					/* vlan_state enabled */
+					count++;
+
+					if (iface->vlan_id)
+						/* For vlan value */
+						count++;
+				} else
+					/* vlan_state disabled */
+					count++;
+
+				if (iface->mtu)
+					count++;
+
+				if (iface->port)
+					count++;
+			}
+		} else
+			/* IPv6 is disabled, iface state */
+			count++;
+	}
+
+	iface_params->count += count;
+	return 0;
+}
+
+/**
+ * iface_get_param_count - Gets netconfig parameter count from iface
+ * @iface: iface to setup
+ * @iface_all: Flag for number of ifaces to traverse (1 for all)
+ *
+ * Returns netconfig parameter count.
+ */
+int iface_get_param_count(struct iface_rec *iface, int iface_all)
+{
+	int num_found = 0, rc;
+	struct iface_param_count iface_params;
+
+	log_debug(8, "In iface_get_param_count\n");
+
+	iface_params.primary = iface;
+	iface_params.count = 0;
+
+	if (iface_all)
+		rc = iface_for_each_iface(&iface_params, 0, &num_found,
+					  __iface_get_param_count);
+	else
+		rc = __iface_get_param_count(&iface_params, iface);
+
+	log_debug(8, "iface_get_param_count: rc = %d, count = %d\n",
+		  rc, iface_params.count);
+	return iface_params.count;
+}
+
+/* IPv4/IPv6 Port: 3260 or User defined */
+static int iface_fill_port(struct iovec *iov, struct iface_rec *iface,
+			   uint32_t iface_type)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+	uint16_t port = 3260;
+
+	len = sizeof(struct iscsi_iface_param_info) + 2;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_PORT;
+	net_param->iface_type = iface_type;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 2;
+	if (iface->port)
+		port = iface->port;
+	memcpy(net_param->value, &port, net_param->len);
+	return 0;
+}
+
+static int iface_fill_mtu(struct iovec *iov, struct iface_rec *iface,
+			  uint32_t iface_type)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+	uint16_t mtu = 0;
+
+	len = sizeof(struct iscsi_iface_param_info) + 2;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_MTU;
+	net_param->iface_type = iface_type;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 2;
+	mtu = iface->mtu;
+	memcpy(net_param->value, &mtu, net_param->len);
+	return 0;
+}
+
+/* IPv4/IPv6 VLAN_ID: decimal value <= 4095 */
+static int iface_fill_vlan_id(struct iovec *iov, struct iface_rec *iface,
+			      uint32_t iface_type)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+	uint16_t vlan = 0;
+
+	len = sizeof(struct iscsi_iface_param_info) + 2;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_VLAN_ID;
+	net_param->iface_type = iface_type;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 2;
+	if (iface->vlan_id <= ISCSI_MAX_VLAN_ID &&
+	    iface->vlan_priority <= ISCSI_MAX_VLAN_PRIORITY)
+		/*
+		 * Bit 15-13: User Priority of VLAN
+		 * Bit 11-00: VLAN ID
+		 */
+		vlan = (iface->vlan_priority << 13) |
+		       (iface->vlan_id & ISCSI_MAX_VLAN_ID);
+	memcpy(net_param->value, &vlan, net_param->len);
+	return 0;
+}
+
+/* IPv4/IPv6 VLAN state: disable/enable */
+static int iface_fill_vlan_state(struct iovec *iov, struct iface_rec *iface,
+				 uint32_t iface_type)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 1;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_VLAN_ENABLED;
+	net_param->iface_type = iface_type;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 1;
+	if (strcmp(iface->vlan_state, "disable") && iface->vlan_id)
+		net_param->value[0] = ISCSI_VLAN_ENABLE;
+	else /* Assume disabled */
+		net_param->value[0] = ISCSI_VLAN_DISABLE;
+	return 0;
+}
+
+/* IPv4/IPv6 Network state: disable/enable */
+static int iface_fill_net_state(struct iovec *iov, struct iface_rec *iface,
+				uint32_t iface_type)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 1;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_IFACE_ENABLE;
+	net_param->iface_type = iface_type;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 1;
+	if (!strcmp(iface->state, "disable"))
+		net_param->value[0] = ISCSI_IFACE_DISABLE;
+	else /* Assume enabled */
+		net_param->value[0] = ISCSI_IFACE_ENABLE;
+	return 0;
+}
+
+/* IPv4 Bootproto: DHCP/static */
+static int iface_fill_net_bootproto(struct iovec *iov, struct iface_rec *iface)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 1;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
+	net_param->iface_type = ISCSI_IFACE_TYPE_IPV4;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 1;
+	if (!strcmp(iface->bootproto, "dhcp"))
+		net_param->value[0] = ISCSI_BOOTPROTO_DHCP;
+	else
+		net_param->value[0] = ISCSI_BOOTPROTO_STATIC;
+	return 0;
+}
+
+/* IPv6 IPAddress Autocfg: nd/dhcpv6/disable */
+static int iface_fill_net_autocfg(struct iovec *iov, struct iface_rec *iface)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 1;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
+	net_param->iface_type = ISCSI_IFACE_TYPE_IPV6;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 1;
+
+	if (!strcmp(iface->ipv6_autocfg, "nd"))
+		net_param->value[0] = ISCSI_IPV6_AUTOCFG_ND_ENABLE;
+	else if (!strcmp(iface->ipv6_autocfg, "dhcpv6"))
+		net_param->value[0] = ISCSI_IPV6_AUTOCFG_DHCPV6_ENABLE;
+	else
+		net_param->value[0] = ISCSI_IPV6_AUTOCFG_DISABLE;
+
+	return 0;
+}
+
+/* IPv6 LinkLocal Autocfg: enable/disable */
+static int iface_fill_linklocal_autocfg(struct iovec *iov,
+					struct iface_rec *iface)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 1;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
+	net_param->iface_type = ISCSI_IFACE_TYPE_IPV6;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 1;
+
+	if (strstr(iface->linklocal_autocfg, "auto"))
+		net_param->value[0] = ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE;
+	else
+		net_param->value[0] = ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE;
+
+	return 0;
+}
+
+/* IPv6 Router Autocfg: enable/disable */
+static int iface_fill_router_autocfg(struct iovec *iov, struct iface_rec *iface)
+{
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 1;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG;
+	net_param->iface_type = ISCSI_IFACE_TYPE_IPV6;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 1;
+
+	if (strstr(iface->router_autocfg, "auto"))
+		net_param->value[0] = ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE;
+	else
+		net_param->value[0] = ISCSI_IPV6_ROUTER_AUTOCFG_DISABLE;
+
+	return 0;
+}
+
+/* IPv4 IPAddress/Subnet Mask/Gateway: 4 bytes */
+static int iface_fill_net_ipv4_addr(struct iovec *iov, struct iface_rec *iface,
+				    uint32_t param)
+{
+	int rc = 1;
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 4;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = param;
+	net_param->iface_type = ISCSI_IFACE_TYPE_IPV4;
+	net_param->iface_num = iface->iface_num;
+	net_param->len = 4;
+	net_param->param_type = ISCSI_NET_PARAM;
+
+	switch (param) {
+	case ISCSI_NET_PARAM_IPV4_ADDR:
+		rc = inet_pton(AF_INET, iface->ipaddress, net_param->value);
+		if (rc <= 0)
+			goto free;
+		break;
+	case ISCSI_NET_PARAM_IPV4_SUBNET:
+		rc = inet_pton(AF_INET, iface->subnet_mask, net_param->value);
+		if (rc <= 0)
+			goto free;
+		break;
+	case ISCSI_NET_PARAM_IPV4_GW:
+		rc = inet_pton(AF_INET, iface->gateway, net_param->value);
+		if (rc <= 0)
+			goto free;
+		break;
+	default:
+		goto free;
+	}
+
+	/* validate */
+	if (!net_param->value[0] && !net_param->value[1] &&
+	    !net_param->value[2] && !net_param->value[3])
+		goto free;
+
+	return 0;
+free:
+	free(iov->iov_base);
+	iov->iov_base = NULL;
+	iov->iov_len = 0;
+	return 1;
+}
+
+/* IPv6 IPAddress/LinkLocal/Router: 16 bytes */
+static int iface_fill_net_ipv6_addr(struct iovec *iov, struct iface_rec *iface,
+				    uint32_t param)
+{
+	int rc;
+	int len;
+	struct iscsi_iface_param_info *net_param;
+
+	len = sizeof(struct iscsi_iface_param_info) + 16;
+	iov->iov_base = calloc(len, sizeof(char));
+	if (!(iov->iov_base))
+		return 1;
+
+	iov->iov_len = len;
+	net_param = (struct iscsi_iface_param_info *)(iov->iov_base);
+	net_param->param = param;
+	net_param->iface_type = ISCSI_IFACE_TYPE_IPV6;
+	net_param->iface_num = iface->iface_num;
+	net_param->param_type = ISCSI_NET_PARAM;
+	net_param->len = 16;
+
+	switch (param) {
+	case ISCSI_NET_PARAM_IPV6_ADDR:
+		rc = inet_pton(AF_INET6, iface->ipaddress, net_param->value);
+		if (rc <= 0)
+			goto free;
+		break;
+	case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
+		rc = inet_pton(AF_INET6, iface->ipv6_linklocal,
+			       net_param->value);
+		if (rc <= 0)
+			goto free;
+		break;
+	case ISCSI_NET_PARAM_IPV6_ROUTER:
+		rc = inet_pton(AF_INET6, iface->ipv6_router, net_param->value);
+		if (rc <= 0)
+			goto free;
+		break;
+	default:
+		goto free;
+	}
+
+	return 0;
+free:
+	free(iov->iov_base);
+	iov->iov_base = NULL;
+	iov->iov_len = 0;
+	return 1;
+}
+
+struct iface_net_config {
+	struct iface_rec *primary;
+	struct iovec *iovs;
+	int count;
+};
+
+static int __iface_build_net_config(void *data, struct iface_rec *iface)
+{
+	struct iface_net_config *net_config = data;
+	struct iovec *iov;
+	int iptype = ISCSI_IFACE_TYPE_IPV4;
+	int count = 0;
+
+	if (strcmp(net_config->primary->hwaddress, iface->hwaddress))
+		return 0;
+
+	if (strcmp(iface->bootproto, "dhcp") && !strstr(iface->ipaddress, "."))
+		iptype = ISCSI_IFACE_TYPE_IPV6;
+
+	/* start at 2, because 0 is for nlmsghdr and 1 for event */
+	iov = net_config->iovs + 2;
+
+	if (iptype == ISCSI_IFACE_TYPE_IPV4) {
+		if (!strcmp(iface->state, "disable")) {
+			if (!iface_fill_net_state(&iov[net_config->count],
+						  iface,
+						  ISCSI_IFACE_TYPE_IPV4)) {
+				net_config->count++;
+				count++;
+			}
+
+			return 0;
+		}
+
+		if (strstr(iface->bootproto, "dhcp")) {
+			if (!iface_fill_net_bootproto(&iov[net_config->count],
+						      iface)) {
+				net_config->count++;
+				count++;
+			}
+		} else if (strstr(iface->ipaddress, ".")) {
+			if (!iface_fill_net_bootproto(&iov[net_config->count],
+						      iface)) {
+				net_config->count++;
+				count++;
+			}
+			if (!iface_fill_net_ipv4_addr(&iov[net_config->count],
+						iface,
+						ISCSI_NET_PARAM_IPV4_ADDR)) {
+				net_config->count++;
+				count++;
+			}
+			if (strstr(iface->subnet_mask, ".")) {
+				if (!iface_fill_net_ipv4_addr(
+						&iov[net_config->count], iface,
+						ISCSI_NET_PARAM_IPV4_SUBNET)) {
+					net_config->count++;
+					count++;
+				}
+			}
+			if (strstr(iface->gateway, ".")) {
+				if (!iface_fill_net_ipv4_addr(
+						&iov[net_config->count], iface,
+						ISCSI_NET_PARAM_IPV4_GW)) {
+					net_config->count++;
+					count++;
+				}
+			}
+		}
+
+		/*
+		 * If IPv4 configuration in iface file is valid,
+		 * fill state and other parameters (if any)
+		 */
+		if (count) {
+			if (!iface_fill_net_state(&iov[net_config->count],
+						  iface,
+						  ISCSI_IFACE_TYPE_IPV4)) {
+				net_config->count++;
+				count++;
+			}
+			if (!iface_fill_vlan_state(&iov[net_config->count],
+						iface,
+						ISCSI_IFACE_TYPE_IPV4)) {
+				net_config->count++;
+				count++;
+			}
+			if (strcmp(iface->vlan_state, "disable") &&
+			    iface->vlan_id) {
+				if (!iface_fill_vlan_id(&iov[net_config->count],
+						iface, ISCSI_IFACE_TYPE_IPV4)) {
+					net_config->count++;
+					count++;
+				}
+			}
+			if (iface->mtu) {
+				if (!iface_fill_mtu(&iov[net_config->count],
+						    iface,
+						    ISCSI_IFACE_TYPE_IPV4)) {
+					net_config->count++;
+					count++;
+				}
+			}
+			if (iface->port) {
+				if (!iface_fill_port(&iov[net_config->count],
+						iface,
+						ISCSI_IFACE_TYPE_IPV4)) {
+					net_config->count++;
+					count++;
+				}
+			}
+		}
+	} else if (iptype == ISCSI_IFACE_TYPE_IPV6) {
+		if (!strcmp(iface->state, "disable")) {
+			if (!iface_fill_net_state(&iov[net_config->count],
+						  iface,
+						  ISCSI_IFACE_TYPE_IPV6)) {
+				net_config->count++;
+				count++;
+			}
+			return 0;
+		}
+
+		/* For IPv6 Address */
+		if (strstr(iface->ipv6_autocfg, "nd") ||
+		    strstr(iface->ipv6_autocfg, "dhcpv6")) {
+			if (!iface_fill_net_autocfg(&iov[net_config->count],
+						    iface)) {
+				net_config->count++;
+				count++;
+			}
+		} else if (strstr(iface->ipaddress, ":")) {
+			if (!iface_fill_net_autocfg(&iov[net_config->count],
+						    iface)) {
+				net_config->count++;
+				count++;
+			}
+			/* User provided IPv6 Address */
+			if (!iface_fill_net_ipv6_addr(&iov[net_config->count],
+						iface,
+						ISCSI_NET_PARAM_IPV6_ADDR)) {
+				net_config->count++;
+				count++;
+			}
+		}
+
+		/* For LinkLocal Address */
+		if (strstr(iface->linklocal_autocfg, "auto")) {
+			if (!iface_fill_linklocal_autocfg(
+						&iov[net_config->count],
+						iface)) {
+				net_config->count++;
+				count++;
+			}
+		} else if (strstr(iface->ipv6_linklocal, ":")) {
+			if (!iface_fill_linklocal_autocfg(
+						&iov[net_config->count],
+						iface)) {
+				net_config->count++;
+				count++;
+			}
+			/* User provided Link Local Address */
+			if (!iface_fill_net_ipv6_addr(&iov[net_config->count],
+					iface,
+					ISCSI_NET_PARAM_IPV6_LINKLOCAL)) {
+				net_config->count++;
+				count++;
+			}
+		}
+
+		/* For Router Address */
+		if (strstr(iface->router_autocfg, "auto")) {
+			if (!iface_fill_router_autocfg(&iov[net_config->count],
+						       iface)) {
+				net_config->count++;
+				count++;
+			}
+		} else if (strstr(iface->ipv6_router, ":")) {
+			if (!iface_fill_router_autocfg(&iov[net_config->count],
+						       iface)) {
+				net_config->count++;
+				count++;
+			}
+			/* User provided Router Address */
+			if (!iface_fill_net_ipv6_addr(&iov[net_config->count],
+						iface,
+						ISCSI_NET_PARAM_IPV6_ROUTER)) {
+				net_config->count++;
+				count++;
+			}
+		}
+
+		/*
+		 * If IPv6 configuration in iface file is valid,
+		 * fill state and other parameters
+		 */
+		if (count) {
+			if (!iface_fill_net_state(&iov[net_config->count],
+						  iface,
+						  ISCSI_IFACE_TYPE_IPV6)) {
+				net_config->count++;
+				count++;
+			}
+			if (!iface_fill_vlan_state(&iov[net_config->count],
+						   iface,
+						   ISCSI_IFACE_TYPE_IPV6)) {
+				net_config->count++;
+				count++;
+			}
+			if (strcmp(iface->vlan_state, "disable") &&
+			    iface->vlan_id) {
+				if (!iface_fill_vlan_id(&iov[net_config->count],
+						iface,
+						ISCSI_IFACE_TYPE_IPV6)) {
+					net_config->count++;
+					count++;
+				}
+			}
+			if (iface->mtu) {
+				if (!iface_fill_mtu(&iov[net_config->count],
+						    iface,
+						    ISCSI_IFACE_TYPE_IPV6)) {
+					net_config->count++;
+					count++;
+				}
+			}
+			if (iface->port) {
+				if (!iface_fill_port(&iov[net_config->count],
+						     iface,
+						     ISCSI_IFACE_TYPE_IPV6)) {
+					net_config->count++;
+					count++;
+				}
+			}
+		}
+	}
+	return 0;
+}
+
+/**
+ * iface_build_net_config - Setup neconfig parameter buffers
+ * @iface: iface to setup
+ * @iface_all: Flag for number of ifaces to traverse (1 for all)
+ * @iovs: iovec buffer for netconfig parameters
+ *
+ * Returns total number of netconfig parameter buffers used.
+ */
+int iface_build_net_config(struct iface_rec *iface, int iface_all,
+			   struct iovec *iovs)
+{
+	int num_found = 0, rc;
+	struct iface_net_config net_config;
+
+	log_debug(8, "In iface_build_net_config\n");
+
+	net_config.primary = iface;
+	net_config.iovs = iovs;
+	net_config.count = 0;
+
+	if (iface_all)
+		rc = iface_for_each_iface(&net_config, 0, &num_found,
+					  __iface_build_net_config);
+	else
+		rc = __iface_build_net_config(&net_config, iface);
+
+	log_debug(8, "iface_build_net_config: rc = %d, count = %d\n",
+		  rc, net_config.count);
+	return net_config.count;
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iface.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iface.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iface.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iface.h	2011-08-14 16:48:25.000000000 -0500
@@ -54,6 +54,10 @@ extern int iface_setup_from_boot_context
                                    struct boot_context *context);
 extern int iface_create_ifaces_from_boot_contexts(struct list_head *ifaces,
 						  struct list_head *targets);
+extern int iface_get_param_count(struct iface_rec *iface_primary,
+				 int iface_all);
+extern int iface_build_net_config(struct iface_rec *iface_primary,
+				  int iface_all, struct iovec *iovs);
 
 #define iface_fmt "[hw=%s,ip=%s,net_if=%s,iscsi_if=%s]"
 #define iface_str(_iface) \
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/initiator.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/initiator.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/initiator.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/initiator.c	2011-08-14 16:48:25.000000000 -0500
@@ -46,6 +46,7 @@
 #include "iscsi_settings.h"
 #include "iface.h"
 #include "sysdeps.h"
+#include "iscsi_err.h"
 
 #define ISCSI_CONN_ERR_REOPEN_DELAY	3
 #define ISCSI_INTERNAL_ERR_REOPEN_DELAY	5
@@ -53,31 +54,17 @@
 #define PROC_DIR "/proc"
 
 static void iscsi_login_timedout(void *data);
+static int iscsi_sched_ev_context(struct iscsi_ev_context *ev_context,
+				  struct iscsi_conn *conn, unsigned long tmo,
+				  int event);
 
-/*
- * calculate parameter's padding
- */
-static unsigned int
-__padding(unsigned int param)
-{
-	int pad;
-
-	pad = param & 3;
-	if (pad) {
-		pad = 4 - pad;
-		log_debug(1, "parameter's value %d padded to %d bytes\n",
-			   param, param + pad);
-	}
-	return param + pad;
-}
-
-static int iscsi_conn_context_alloc(iscsi_conn_t *conn)
+static int iscsi_ev_context_alloc(iscsi_conn_t *conn)
 {
 	int i;
 
 	for (i = 0; i < CONTEXT_POOL_MAX; i++) {
 		conn->context_pool[i] = calloc(1,
-					   sizeof(struct iscsi_conn_context) +
+					   sizeof(struct iscsi_ev_context) +
 					   ipc->ctldev_bufmax);
 		if (!conn->context_pool[i]) {
 			int j;
@@ -91,7 +78,7 @@ static int iscsi_conn_context_alloc(iscs
 	return 0;
 }
 
-static void iscsi_conn_context_free(iscsi_conn_t *conn)
+static void iscsi_ev_context_free(iscsi_conn_t *conn)
 {
 	int i;
 
@@ -107,10 +94,10 @@ static void iscsi_conn_context_free(iscs
 	}
 }
 
-struct iscsi_conn_context *iscsi_conn_context_get(iscsi_conn_t *conn,
-						  int ev_size)
+static struct iscsi_ev_context *
+iscsi_ev_context_get(iscsi_conn_t *conn, int ev_size)
 {
-	struct iscsi_conn_context *conn_context;
+	struct iscsi_ev_context *ev_context;
 	int i;
 
 	if (ev_size > ipc->ctldev_bufmax)
@@ -121,26 +108,26 @@ struct iscsi_conn_context *iscsi_conn_co
 			continue;
 
 		if (!conn->context_pool[i]->allocated) {
-			conn_context = conn->context_pool[i];
+			ev_context = conn->context_pool[i];
 
-			memset(&conn_context->actor, 0,
+			memset(&ev_context->actor, 0,
 				sizeof(struct actor));
-			conn_context->allocated = 1;
+			ev_context->allocated = 1;
 			/* some callers abuse this pointer */
-			conn_context->data = (void *)conn_context +
-					sizeof(struct iscsi_conn_context);
-			log_debug(7, "get conn context %p",
-				  &conn_context->actor);
-			return conn_context;
+			ev_context->data = (void *)ev_context +
+					sizeof(struct iscsi_ev_context);
+			log_debug(7, "get ev context %p",
+				  &ev_context->actor);
+			return ev_context;
 		}
 	}
 	return NULL;
 }
 
-void iscsi_conn_context_put(struct iscsi_conn_context *conn_context)
+static void iscsi_ev_context_put(struct iscsi_ev_context *ev_context)
 {
-	log_debug(7, "put conn context %p", &conn_context->actor);
-	conn_context->allocated = 0;
+	log_debug(7, "put ev context %p", &ev_context->actor);
+	ev_context->allocated = 0;
 }
 
 static void session_online_devs(int host_no, int sid)
@@ -205,11 +192,11 @@ __check_iscsi_status_class(iscsi_session
 			log_error("session %d login rejected: Initiator "
 			       "failed authentication with target",
 				session->id);
-			return CONN_LOGIN_FAILED;
+			return CONN_LOGIN_AUTH_FAILED;
 		case ISCSI_LOGIN_STATUS_TGT_FORBIDDEN:
 			log_error("conn %d login rejected: initiator "
 			       "failed authorization with target", conn->id);
-			return CONN_LOGIN_FAILED;
+			return CONN_LOGIN_AUTH_FAILED;
 		case ISCSI_LOGIN_STATUS_TGT_NOT_FOUND:
 			log_error("conn %d login rejected: initiator "
 			       "error - target not found (%02x/%02x)",
@@ -250,183 +237,6 @@ __check_iscsi_status_class(iscsi_session
 	return CONN_LOGIN_FAILED;
 }
 
-static void
-__setup_authentication(iscsi_session_t *session,
-			struct iscsi_auth_config *auth_cfg)
-{
-	/* if we have any incoming credentials, we insist on authenticating
-	 * the target or not logging in at all
-	 */
-	if (auth_cfg->username_in[0]
-	    || auth_cfg->password_in_length) {
-		/* sanity check the config */
-		if (auth_cfg->password_length == 0) {
-			log_debug(1,
-			       "node record has incoming "
-			       "authentication credentials but has no outgoing "
-			       "credentials configured, exiting");
-			return;
-		}
-		session->bidirectional_auth = 1;
-	} else {
-		/* no or 1-way authentication */
-		session->bidirectional_auth = 0;
-	}
-
-	/* copy in whatever credentials we have */
-	strlcpy(session->username, auth_cfg->username,
-		sizeof (session->username));
-	session->username[sizeof (session->username) - 1] = '\0';
-	if ((session->password_length = auth_cfg->password_length))
-		memcpy(session->password, auth_cfg->password,
-		       session->password_length);
-
-	strlcpy(session->username_in, auth_cfg->username_in,
-		sizeof (session->username_in));
-	session->username_in[sizeof (session->username_in) - 1] = '\0';
-	if ((session->password_in_length =
-	     auth_cfg->password_in_length))
-		memcpy(session->password_in, auth_cfg->password_in,
-		       session->password_in_length);
-
-	if (session->password_length || session->password_in_length) {
-		/* setup the auth buffers */
-		session->auth_buffers[0].address = &session->auth_client_block;
-		session->auth_buffers[0].length =
-		    sizeof (session->auth_client_block);
-		session->auth_buffers[1].address =
-		    &session->auth_recv_string_block;
-		session->auth_buffers[1].length =
-		    sizeof (session->auth_recv_string_block);
-
-		session->auth_buffers[2].address =
-		    &session->auth_send_string_block;
-		session->auth_buffers[2].length =
-		    sizeof (session->auth_send_string_block);
-
-		session->auth_buffers[3].address =
-		    &session->auth_recv_binary_block;
-		session->auth_buffers[3].length =
-		    sizeof (session->auth_recv_binary_block);
-
-		session->auth_buffers[4].address =
-		    &session->auth_send_binary_block;
-		session->auth_buffers[4].length =
-		    sizeof (session->auth_send_binary_block);
-
-		session->num_auth_buffers = 5;
-		log_debug(6, "authentication setup complete...");
-	} else {
-		session->num_auth_buffers = 0;
-		log_debug(6, "no authentication configured...");
-	}
-}
-
-static int
-setup_portal(iscsi_conn_t *conn, conn_rec_t *conn_rec)
-{
-	char port[NI_MAXSERV];
-
-	sprintf(port, "%d", conn_rec->port);
-	if (resolve_address(conn_rec->address, port, &conn->saddr)) {
-		log_error("cannot resolve host name %s",
-			  conn_rec->address);
-		return EINVAL;
-	}
-	conn->failback_saddr = conn->saddr;
-
-	getnameinfo((struct sockaddr *)&conn->saddr, sizeof(conn->saddr),
-		    conn->host, sizeof(conn->host), NULL, 0, NI_NUMERICHOST);
-	log_debug(4, "resolved %s to %s", conn_rec->address, conn->host);
-	return 0;
-}
-
-static void
-iscsi_copy_operational_params(iscsi_conn_t *conn)
-{
-	iscsi_session_t *session = conn->session;
-	conn_rec_t *conn_rec = &session->nrec.conn[conn->id];
-	node_rec_t *rec = &session->nrec;
-
-	conn->hdrdgst_en = conn_rec->iscsi.HeaderDigest;
-	conn->datadgst_en = conn_rec->iscsi.DataDigest;
-
-	conn->max_recv_dlength =
-			__padding(conn_rec->iscsi.MaxRecvDataSegmentLength);
-	if (conn->max_recv_dlength < ISCSI_MIN_MAX_RECV_SEG_LEN ||
-	    conn->max_recv_dlength > ISCSI_MAX_MAX_RECV_SEG_LEN) {
-		log_error("Invalid iscsi.MaxRecvDataSegmentLength. Must be "
-			 "within %u and %u. Setting to %u\n",
-			  ISCSI_MIN_MAX_RECV_SEG_LEN,
-			  ISCSI_MAX_MAX_RECV_SEG_LEN,
-			  DEF_INI_MAX_RECV_SEG_LEN);
-		conn_rec->iscsi.MaxRecvDataSegmentLength =
-						DEF_INI_MAX_RECV_SEG_LEN;
-		conn->max_recv_dlength = DEF_INI_MAX_RECV_SEG_LEN;
-	}
-
-	/* zero indicates to use the target's value */
-	conn->max_xmit_dlength =
-			__padding(conn_rec->iscsi.MaxXmitDataSegmentLength);
-	if (conn->max_xmit_dlength == 0)
-		conn->max_xmit_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN;
-	if (conn->max_xmit_dlength < ISCSI_MIN_MAX_RECV_SEG_LEN ||
-	    conn->max_xmit_dlength > ISCSI_MAX_MAX_RECV_SEG_LEN) {
-		log_error("Invalid iscsi.MaxXmitDataSegmentLength. Must be "
-			 "within %u and %u. Setting to %u\n",
-			  ISCSI_MIN_MAX_RECV_SEG_LEN,
-			  ISCSI_MAX_MAX_RECV_SEG_LEN,
-			  DEF_INI_MAX_RECV_SEG_LEN);
-		conn_rec->iscsi.MaxXmitDataSegmentLength =
-						DEF_INI_MAX_RECV_SEG_LEN;
-		conn->max_xmit_dlength = DEF_INI_MAX_RECV_SEG_LEN;
-	}
-
-	/* session's operational parameters */
-	session->initial_r2t_en = rec->session.iscsi.InitialR2T;
-	session->imm_data_en = rec->session.iscsi.ImmediateData;
-	session->first_burst = __padding(rec->session.iscsi.FirstBurstLength);
-	/*
-	 * some targets like netapp fail the login if sent bad first_burst
-	 * and max_burst lens, even when immediate data=no and
-	 * initial r2t = Yes, so we always check the user values.
-	 */
-	if (session->first_burst < ISCSI_MIN_FIRST_BURST_LEN ||
-	    session->first_burst > ISCSI_MAX_FIRST_BURST_LEN) {
-		log_error("Invalid iscsi.FirstBurstLength of %u. Must be "
-			 "within %u and %u. Setting to %u\n",
-			  session->first_burst,
-			  ISCSI_MIN_FIRST_BURST_LEN,
-			  ISCSI_MAX_FIRST_BURST_LEN,
-			  DEF_INI_FIRST_BURST_LEN);
-		rec->session.iscsi.FirstBurstLength = DEF_INI_FIRST_BURST_LEN;
-		session->first_burst = DEF_INI_FIRST_BURST_LEN;
-	}
-
-	session->max_burst = __padding(rec->session.iscsi.MaxBurstLength);
-	if (session->max_burst < ISCSI_MIN_MAX_BURST_LEN ||
-	    session->max_burst > ISCSI_MAX_MAX_BURST_LEN) {
-		log_error("Invalid iscsi.MaxBurstLength of %u. Must be "
-			  "within %u and %u. Setting to %u\n",
-			   session->max_burst, ISCSI_MIN_MAX_BURST_LEN,
-			   ISCSI_MAX_MAX_BURST_LEN, DEF_INI_MAX_BURST_LEN);
-		rec->session.iscsi.MaxBurstLength = DEF_INI_MAX_BURST_LEN;
-		session->max_burst = DEF_INI_MAX_BURST_LEN;
-	}
-
-	if (session->first_burst > session->max_burst) {
-		log_error("Invalid iscsi.FirstBurstLength of %u. Must be "
-			  "less than iscsi.MaxBurstLength. Setting to %u\n",
-			   session->first_burst, session->max_burst);
-		rec->session.iscsi.FirstBurstLength = session->max_burst;
-		session->first_burst = session->max_burst;
-	}
-
-	session->def_time2wait = rec->session.iscsi.DefaultTime2Wait;
-	session->def_time2retain = rec->session.iscsi.DefaultTime2Retain;
-	session->erl = rec->session.iscsi.ERL;
-}
-
 static int
 __session_conn_create(iscsi_session_t *session, int cid)
 {
@@ -434,12 +244,12 @@ __session_conn_create(iscsi_session_t *s
 	conn_rec_t *conn_rec = &session->nrec.conn[cid];
 	int err;
 
-	if (iscsi_conn_context_alloc(conn)) {
+	if (iscsi_ev_context_alloc(conn)) {
 		log_error("cannot allocate context_pool for conn cid %d", cid);
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	}
 
-	conn->state = STATE_FREE;
+	conn->state = ISCSI_CONN_STATE_FREE;
 	conn->session = session;
 	/*
 	 * TODO: we must export the socket_fd/transport_eph from sysfs
@@ -486,14 +296,15 @@ __session_conn_create(iscsi_session_t *s
 		conn->noop_out_interval = DEF_NOOP_OUT_INTERVAL;
 	}
 
-	iscsi_copy_operational_params(conn);
+	iscsi_copy_operational_params(conn, &session->nrec.session.iscsi,
+				      &conn_rec->iscsi);
 
 	/* TCP options */
 	conn->tcp_window_size = conn_rec->tcp.window_size;
 	/* FIXME: type_of_service */
 
 	/* resolve the string address to an IP address */
-	err = setup_portal(conn, conn_rec);
+	err = iscsi_setup_portal(conn, conn_rec->address, conn_rec->port);
 	if (err)
 		return err;
 	return 0;
@@ -506,7 +317,7 @@ session_release(iscsi_session_t *session
 
 	if (session->target_alias)
 		free(session->target_alias);
-	iscsi_conn_context_free(&session->conn[0]);
+	iscsi_ev_context_free(&session->conn[0]);
 	free(session);
 }
 
@@ -524,11 +335,10 @@ __session_create(node_rec_t *rec, struct
 	log_debug(2, "Allocted session %p", session);
 
 	INIT_LIST_HEAD(&session->list);
-	/* opened at daemon load time (iscsid.c) */
-	session->ctrl_fd = control_fd;
 	session->t = t;
 	session->reopen_qtask.mgmt_ipc_fd = -1;
 	session->id = -1;
+	session->use_ipc = 1;
 
 	/* save node record. we might need it for redirection */
 	memcpy(&session->nrec, rec, sizeof(node_rec_t));
@@ -570,7 +380,7 @@ __session_create(node_rec_t *rec, struct
 	session->isid[5] = 0;
 
 	/* setup authentication variables for the session*/
-	__setup_authentication(session, &rec->session.auth);
+	iscsi_setup_authentication(session, &rec->session.auth);
 
 	session->param_mask = ~0ULL;
 	if (!(t->caps & CAP_MULTI_R2T))
@@ -601,18 +411,18 @@ __session_create(node_rec_t *rec, struct
 
 static void iscsi_flush_context_pool(struct iscsi_session *session)
 {
-	struct iscsi_conn_context *conn_context;
+	struct iscsi_ev_context *ev_context;
 	struct iscsi_conn *conn = &session->conn[0];
 	int i;
 
 	for (i = 0; i < CONTEXT_POOL_MAX; i++) {
-		conn_context = conn->context_pool[i];
-		if (!conn_context)
+		ev_context = conn->context_pool[i];
+		if (!ev_context)
 			continue;
 
-		if (conn_context->allocated) {
+		if (ev_context->allocated) {
 			actor_delete(&(conn->context_pool[i]->actor));
-			iscsi_conn_context_put(conn_context);
+			iscsi_ev_context_put(ev_context);
 		}
 	}
 }
@@ -633,15 +443,16 @@ conn_delete_timers(iscsi_conn_t *conn)
 	actor_delete(&conn->nop_out_timer);
 }
 
-static mgmt_ipc_err_e
+static int 
 session_conn_shutdown(iscsi_conn_t *conn, queue_task_t *qtask,
-		      mgmt_ipc_err_e err)
+		      int err)
 {
 	iscsi_session_t *session = conn->session;
 
 	log_debug(2, "disconnect conn");
 	/* this will check for a valid interconnect connection */
-	conn->session->t->template->ep_disconnect(conn);
+	if (session->t->template->ep_disconnect)
+		session->t->template->ep_disconnect(conn);
 
 	if (session->id == -1)
 		goto cleanup;
@@ -649,15 +460,15 @@ session_conn_shutdown(iscsi_conn_t *conn
 	if (!iscsi_sysfs_session_has_leadconn(session->id))
 		goto cleanup;
 
-	if (conn->state == STATE_IN_LOGIN ||
-	    conn->state == STATE_IN_LOGOUT ||
-	    conn->state == STATE_LOGGED_IN) {
+	if (conn->state == ISCSI_CONN_STATE_IN_LOGIN ||
+	    conn->state == ISCSI_CONN_STATE_IN_LOGOUT ||
+	    conn->state == ISCSI_CONN_STATE_LOGGED_IN) {
 		log_debug(2, "stop conn (conn state %d)", conn->state);
 		if (ipc->stop_conn(session->t->handle, session->id,
 				   conn->id, STOP_CONN_TERM)) {
 			log_error("can't stop connection %d:%d (%d)",
 				  session->id, conn->id, errno);
-			return MGMT_IPC_ERR_INTERNAL;
+			return ISCSI_ERR_INTERNAL;
 		}
 	}
 
@@ -665,16 +476,18 @@ session_conn_shutdown(iscsi_conn_t *conn
 	if (ipc->destroy_conn(session->t->handle, session->id,
 		conn->id)) {
 		log_error("can not safely destroy connection %d", conn->id);
-		return MGMT_IPC_ERR_INTERNAL;
+		return ISCSI_ERR_INTERNAL;
 	}
 
 cleanup:
 	if (session->id != -1) {
 		log_debug(2, "kdestroy session %u", session->id);
-		if (ipc->destroy_session(session->t->handle, session->id)) {
+		session->r_stage = R_STAGE_SESSION_DESTOYED;
+		err = ipc->destroy_session(session->t->handle, session->id);
+		if (err) {
 			log_error("can not safely destroy session %d",
 				  session->id);
-			return MGMT_IPC_ERR_INTERNAL;
+			return ISCSI_ERR_INTERNAL;
 		}
 	}
 
@@ -688,7 +501,7 @@ cleanup:
 	mgmt_ipc_write_rsp(qtask, err);
 	conn_delete_timers(conn);
 	__session_destroy(session);
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
 static void
@@ -709,17 +522,17 @@ queue_delayed_reopen(queue_task_t *qtask
 
 static int iscsi_conn_connect(struct iscsi_conn *conn, queue_task_t *qtask)
 {
-	struct iscsi_conn_context *conn_context;
+	struct iscsi_ev_context *ev_context;
 	int rc;
 
-	conn_context = iscsi_conn_context_get(conn, 0);
-	if (!conn_context) {
+	ev_context = iscsi_ev_context_get(conn, 0);
+	if (!ev_context) {
 		/* while reopening the recv pool should be full */
 		log_error("BUG: __session_conn_reopen could not get conn "
 			  "context for recv.");
 		return ENOMEM;
 	}
-	conn_context->data = qtask;
+	ev_context->data = qtask;
 
 	rc = conn->session->t->template->ep_connect(conn, 1);
 	if (rc < 0 && errno != EINPROGRESS) {
@@ -732,11 +545,11 @@ static int iscsi_conn_connect(struct isc
 
 		log_error("cannot make a connection to %s:%s (%d,%d)",
 			  conn->host, serv, rc, errno);
-		iscsi_conn_context_put(conn_context);
+		iscsi_ev_context_put(ev_context);
 		return ENOTCONN;
 	}
 
-	iscsi_sched_conn_context(conn_context, conn, 0, EV_CONN_POLL);
+	iscsi_sched_ev_context(ev_context, conn, 0, EV_CONN_POLL);
 	log_debug(3, "Setting login timer %p timeout %d", &conn->login_timer,
 		  conn->login_timeout);
 	actor_timer(&conn->login_timer, conn->login_timeout * 1000,
@@ -759,11 +572,11 @@ __session_conn_reopen(iscsi_conn_t *conn
 	/* flush stale polls or errors queued */
 	iscsi_flush_context_pool(session);
 	conn_delete_timers(conn);
-	conn->state = STATE_XPT_WAIT;
+	conn->state = ISCSI_CONN_STATE_XPT_WAIT;
 
 	conn->session->t->template->ep_disconnect(conn);
 	if (do_stop) {
-		/* state: STATE_CLEANUP_WAIT */
+		/* state: ISCSI_CONN_STATE_CLEANUP_WAIT */
 		if (ipc->stop_conn(session->t->handle, session->id,
 				   conn->id, do_stop)) {
 			log_error("can't stop connection %d:%d (%d)",
@@ -844,8 +657,16 @@ static int iscsi_retry_initial_login(str
 	return 1;
 }
 
+static int iscsi_login_is_fatal_err(int err)
+{
+	if (err == ISCSI_ERR_LOGIN_AUTH_FAILED ||
+	    err == ISCSI_ERR_FATAL_LOGIN)
+		return 1;
+	return 0;
+}
+
 static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask,
-			   mgmt_ipc_err_e err)
+			   int err)
 {
 	struct iscsi_session *session = conn->session;
 
@@ -856,14 +677,14 @@ static void iscsi_login_eh(struct iscsi_
 	iscsi_flush_context_pool(conn->session);
 
 	switch (conn->state) {
-	case STATE_XPT_WAIT:
+	case ISCSI_CONN_STATE_XPT_WAIT:
 		switch (session->r_stage) {
 		case R_STAGE_NO_CHANGE:
-			log_debug(6, "login failed STATE_XPT_WAIT/"
+			log_debug(6, "login failed ISCSI_CONN_STATE_XPT_WAIT/"
 				  "R_STAGE_NO_CHANGE");
 			/* timeout during initial connect.
 			 * clean connection. write ipc rsp or retry */
-			if (err == MGMT_IPC_ERR_FATAL_LOGIN_FAILURE ||
+			if (iscsi_login_is_fatal_err(err) ||
 			    !iscsi_retry_initial_login(conn))
 				session_conn_shutdown(conn, qtask, err);
 			else {
@@ -875,18 +696,18 @@ static void iscsi_login_eh(struct iscsi_
 			}
 			break;
 		case R_STAGE_SESSION_REDIRECT:
-			log_debug(6, "login failed STATE_XPT_WAIT/"
+			log_debug(6, "login failed ISCSI_CONN_STATE_XPT_WAIT/"
 				  "R_STAGE_SESSION_REDIRECT");
 			/* timeout during initial redirect connect
 			 * clean connection. write ipc rsp or retry */
-			if (err == MGMT_IPC_ERR_FATAL_LOGIN_FAILURE ||
+			if (iscsi_login_is_fatal_err(err) ||
 			    !iscsi_retry_initial_login(conn))
 				session_conn_shutdown(conn, qtask, err);
 			else
 				session_conn_reopen(conn, qtask, 0);
 			break;
 		case R_STAGE_SESSION_REOPEN:
-			log_debug(6, "login failed STATE_XPT_WAIT/"
+			log_debug(6, "login failed ISCSI_CONN_STATE_XPT_WAIT/"
 				  "R_STAGE_SESSION_REOPEN %d",
 				  session->reopen_cnt);
 			/* timeout during reopen connect. try again */
@@ -900,11 +721,11 @@ static void iscsi_login_eh(struct iscsi_
 		}
 
 		break;
-	case STATE_IN_LOGIN:
+	case ISCSI_CONN_STATE_IN_LOGIN:
 		switch (session->r_stage) {
 		case R_STAGE_NO_CHANGE:
 		case R_STAGE_SESSION_REDIRECT:
-			log_debug(6, "login failed STATE_IN_LOGIN/"
+			log_debug(6, "login failed ISCSI_CONN_STATE_IN_LOGIN/"
 				  "R_STAGE_NO_CHANGE %d",
 				  session->reopen_cnt);
 			/*
@@ -912,7 +733,7 @@ static void iscsi_login_eh(struct iscsi_
 			 * initial redirected connect. Clean connection
 			 * and write rsp or retry.
 			 */
-			if (err == MGMT_IPC_ERR_FATAL_LOGIN_FAILURE ||
+			if (iscsi_login_is_fatal_err(err) ||
 			    !iscsi_retry_initial_login(conn))
 				session_conn_shutdown(conn, qtask, err);
 			else
@@ -920,14 +741,14 @@ static void iscsi_login_eh(struct iscsi_
 						    STOP_CONN_RECOVER);
 			break;
 		case R_STAGE_SESSION_REOPEN:
-			log_debug(6, "login failed STATE_IN_LOGIN/"
+			log_debug(6, "login failed ISCSI_CONN_STATE_IN_LOGIN/"
 				  "R_STAGE_SESSION_REOPEN %d",
 				  session->reopen_cnt);
 			session_conn_reopen(conn, qtask, STOP_CONN_RECOVER);
 			break;
 		case R_STAGE_SESSION_CLEANUP:
 			session_conn_shutdown(conn, qtask,
-					      MGMT_IPC_ERR_PDU_TIMEOUT);
+					      ISCSI_ERR_PDU_TIMEOUT);
 			break;
 		default:
 			break;
@@ -951,23 +772,23 @@ __conn_error_handle(iscsi_session_t *ses
 	 * just cleanup and return to the user.
 	 */
 	if (conn->logout_qtask) {
-		session_conn_shutdown(conn, conn->logout_qtask, MGMT_IPC_OK);
+		session_conn_shutdown(conn, conn->logout_qtask, ISCSI_SUCCESS);
 		return;
 	}
 
 	switch (conn->state) {
-	case STATE_IN_LOGOUT:
+	case ISCSI_CONN_STATE_IN_LOGOUT:
 		/* logout was from eh - fall down to cleanup */
-	case STATE_LOGGED_IN:
+	case ISCSI_CONN_STATE_LOGGED_IN:
 		/* mark failed connection */
-		conn->state = STATE_CLEANUP_WAIT;
+		conn->state = ISCSI_CONN_STATE_CLEANUP_WAIT;
 
 		if (session->erl > 0) {
 			/* check if we still have some logged in connections */
 			for (i=0; i<ISCSI_CONN_MAX; i++) {
-				if (session->conn[i].state == STATE_LOGGED_IN) {
+				if (session->conn[i].state ==
+				    ISCSI_CONN_STATE_LOGGED_IN)
 					break;
-				}
 			}
 			if (i != ISCSI_CONN_MAX) {
 				/* FIXME: re-assign leading connection
@@ -979,30 +800,32 @@ __conn_error_handle(iscsi_session_t *ses
 
 		/* mark all connections as failed */
 		for (i=0; i<ISCSI_CONN_MAX; i++) {
-			if (session->conn[i].state == STATE_LOGGED_IN)
-				session->conn[i].state = STATE_CLEANUP_WAIT;
+			if (session->conn[i].state ==
+			    ISCSI_CONN_STATE_LOGGED_IN)
+				session->conn[i].state =
+						ISCSI_CONN_STATE_CLEANUP_WAIT;
 		}
 		session->r_stage = R_STAGE_SESSION_REOPEN;
 		break;
-	case STATE_IN_LOGIN:
+	case ISCSI_CONN_STATE_IN_LOGIN:
 		if (session->r_stage == R_STAGE_SESSION_REOPEN) {
 			queue_task_t *qtask;
 
-			if (session->sync_qtask)
-				qtask = session->sync_qtask;
+			if (session->notify_qtask)
+				qtask = session->notify_qtask;
 			else
 				qtask = &session->reopen_qtask;
-			iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_TRANS_FAILURE);
+			iscsi_login_eh(conn, qtask, ISCSI_ERR_TRANS);
 			return;
 		}
 		log_debug(1, "ignoring conn error in login. "
 			  "let it timeout");
 		return;
-	case STATE_XPT_WAIT:
+	case ISCSI_CONN_STATE_XPT_WAIT:
 		log_debug(1, "ignoring conn error in XPT_WAIT. "
 			  "let connection fail on its own");
 		return;
-	case STATE_CLEANUP_WAIT:
+	case ISCSI_CONN_STATE_CLEANUP_WAIT:
 		log_debug(1, "ignoring conn error in CLEANUP_WAIT. "
 			  "let connection stop");
 		return;
@@ -1020,19 +843,19 @@ __conn_error_handle(iscsi_session_t *ses
 
 static void session_conn_error(void *data)
 {
-	struct iscsi_conn_context *conn_context = data;
-	enum iscsi_err error = *(enum iscsi_err *)conn_context->data;
-	iscsi_conn_t *conn = conn_context->conn;
+	struct iscsi_ev_context *ev_context = data;
+	enum iscsi_err error = *(enum iscsi_err *)ev_context->data;
+	iscsi_conn_t *conn = ev_context->conn;
 	iscsi_session_t *session = conn->session;
 
 	log_warning("Kernel reported iSCSI connection %d:%d error (%d) "
 		    "state (%d)", session->id, conn->id, error,
 		    conn->state);
-	iscsi_conn_context_put(conn_context);
+	iscsi_ev_context_put(ev_context);
 
 	switch (error) {
 	case ISCSI_ERR_INVALID_HOST:
-		if (session_conn_shutdown(conn, NULL, MGMT_IPC_OK))
+		if (session_conn_shutdown(conn, NULL, ISCSI_SUCCESS))
 			log_error("BUG: Could not shutdown session.");
 		break;
 	default:
@@ -1046,14 +869,14 @@ static void iscsi_login_timedout(void *d
 	struct iscsi_conn *conn = qtask->conn;
 
 	switch (conn->state) {
-	case STATE_XPT_WAIT:
-		iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_TRANS_TIMEOUT);
+	case ISCSI_CONN_STATE_XPT_WAIT:
+		iscsi_login_eh(conn, qtask, ISCSI_ERR_TRANS_TIMEOUT);
 		break;
-	case STATE_IN_LOGIN:
-		iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_PDU_TIMEOUT);
+	case ISCSI_CONN_STATE_IN_LOGIN:
+		iscsi_login_eh(conn, qtask, ISCSI_ERR_PDU_TIMEOUT);
 		break;
 	default:
-		iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_INTERNAL);
+		iscsi_login_eh(conn, qtask, ISCSI_ERR_INTERNAL);
 		break;
 	}
 }
@@ -1125,7 +948,7 @@ static void conn_send_nop_out(void *data
 	 * we cannot start new request during logout and the logout timer
 	 * will figure things out.
 	 */
-	if (conn->state == STATE_IN_LOGOUT)
+	if (conn->state == ISCSI_CONN_STATE_IN_LOGOUT)
 		return;
 
 	__send_nopout(conn);
@@ -1136,17 +959,6 @@ static void conn_send_nop_out(void *data
 		 &conn->nop_out_timer, conn->noop_out_timeout);
 }
 
-static void
-print_param_value(enum iscsi_param param, void *value, int type)
-{
-	log_debug(3, "set operational parameter %d to:", param);
-
-	if (type == ISCSI_STRING)
-		log_debug(3, "%s", value ? (char *)value : "NULL");
-	else
-		log_debug(3, "%u", *(uint32_t *)value);
-}
-
 void free_initiator(void)
 {
 	struct iscsi_transport *t;
@@ -1170,7 +982,7 @@ static void session_scan_host(struct isc
 
 	pid = iscsi_sysfs_scan_host(hostno, 1);
 	if (pid == 0) {
-		mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK);
+		mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
 
 		if (session)
 			iscsi_sysfs_for_each_device(
@@ -1185,306 +997,37 @@ static void session_scan_host(struct isc
 			free(qtask);
 		}
 	} else
-		mgmt_ipc_write_rsp(qtask, MGMT_IPC_ERR_INTERNAL);
-}
-
-static int __iscsi_host_set_param(struct iscsi_transport *t,
-				  int host_no, int param, char *value,
-				  int type)
-{
-	int rc;
-
-	rc = ipc->set_host_param(t->handle, host_no, param, value, type);
-	/* 2.6.20 and below returns EINVAL */
-	if (rc && rc != -ENOSYS && rc != -EINVAL) {
-		log_error("can't set operational parameter %d for "
-			  "host %d, retcode %d (%d)", param, host_no,
-			  rc, errno);
-		return rc;
-	}
-	return 0;
-}
-
-mgmt_ipc_err_e iscsi_host_set_param(int host_no, int param, char *value)
-{
-	struct iscsi_transport *t;
-
-	t = iscsi_sysfs_get_transport_by_hba(host_no);
-	if (!t)
-		return MGMT_IPC_ERR_TRANS_FAILURE;
-	if (__iscsi_host_set_param(t, host_no, param, value, ISCSI_STRING))
-		return MGMT_IPC_ERR;
-        return MGMT_IPC_OK;
+		mgmt_ipc_write_rsp(qtask, ISCSI_ERR_INTERNAL);
 }
 
-#define MAX_SESSION_PARAMS 32
-#define MAX_HOST_PARAMS 3
-
 static void
 setup_full_feature_phase(iscsi_conn_t *conn)
 {
 	iscsi_session_t *session = conn->session;
 	iscsi_login_context_t *c = &conn->login_context;
-	int i, rc;
-	uint32_t one = 1, zero = 0;
-	struct hostparam {
-		int param;
-		int type;
-		void *value;
-		int set;
-	} hosttbl[MAX_HOST_PARAMS] = {
-		{
-			.param = ISCSI_HOST_PARAM_NETDEV_NAME,
-			.value = session->nrec.iface.netdev,
-			.type = ISCSI_STRING,
-			.set = 1,
-		}, {
-			.param = ISCSI_HOST_PARAM_HWADDRESS,
-			.value = session->nrec.iface.hwaddress,
-			.type = ISCSI_STRING,
-			.set = 1,
-		}, {
-			.param = ISCSI_HOST_PARAM_INITIATOR_NAME,
-			.value = session->initiator_name,
-			.type = ISCSI_STRING,
-			.set = 0,
-		},
-	};
-	struct connparam {
-		int param;
-		int type;
-		void *value;
-		int conn_only;
-	} conntbl[MAX_SESSION_PARAMS] = {
-		{
-			.param = ISCSI_PARAM_MAX_RECV_DLENGTH,
-			.value = &conn->max_recv_dlength,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_MAX_XMIT_DLENGTH,
-			.value = &conn->max_xmit_dlength,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_HDRDGST_EN,
-			.value = &conn->hdrdgst_en,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_DATADGST_EN,
-			.value = &conn->datadgst_en,
-			.type = ISCSI_INT,
-			.conn_only = 1,
-		}, {
-			.param = ISCSI_PARAM_INITIAL_R2T_EN,
-			.value = &session->initial_r2t_en,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_MAX_R2T,
-			.value = &one, /* FIXME: session->max_r2t */
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_IMM_DATA_EN,
-			.value = &session->imm_data_en,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_FIRST_BURST,
-			.value = &session->first_burst,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_MAX_BURST,
-			.value = &session->max_burst,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_PDU_INORDER_EN,
-			.value = &session->pdu_inorder_en,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param =ISCSI_PARAM_DATASEQ_INORDER_EN,
-			.value = &session->dataseq_inorder_en,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_ERL,
-			.value = &zero, /* FIXME: session->erl */
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_IFMARKER_EN,
-			.value = &zero,/* FIXME: session->ifmarker_en */
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_OFMARKER_EN,
-			.value = &zero,/* FIXME: session->ofmarker_en */
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_EXP_STATSN,
-			.value = &conn->exp_statsn,
-			.type = ISCSI_INT,
-			.conn_only = 1,
-		}, {
-			.param = ISCSI_PARAM_TARGET_NAME,
-			.conn_only = 0,
-			.type = ISCSI_STRING,
-			.value = session->target_name,
-		}, {
-			.param = ISCSI_PARAM_TPGT,
-			.value = &session->portal_group_tag,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_PERSISTENT_ADDRESS,
-			.value = session->nrec.conn[conn->id].address,
-			.type = ISCSI_STRING,
-			.conn_only = 1,
-		}, {
-			.param = ISCSI_PARAM_PERSISTENT_PORT,
-			.value = &session->nrec.conn[conn->id].port,
-			.type = ISCSI_INT,
-			.conn_only = 1,
-		}, {
-			.param = ISCSI_PARAM_SESS_RECOVERY_TMO,
-			.value = &session->replacement_timeout,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_USERNAME,
-			.value = session->username,
-			.type = ISCSI_STRING,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_USERNAME_IN,
-			.value = session->username_in,
-			.type = ISCSI_STRING,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_PASSWORD,
-			.value = session->password,
-			.type = ISCSI_STRING,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_PASSWORD_IN,
-			.value = session->password_in,
-			.type = ISCSI_STRING,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_FAST_ABORT,
-			.value = &session->fast_abort,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_ABORT_TMO,
-			.value = &session->abort_timeout,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_LU_RESET_TMO,
-			.value = &session->lu_reset_timeout,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_TGT_RESET_TMO,
-			.value = &session->tgt_reset_timeout,
-			.type = ISCSI_INT,
-			.conn_only = 0,
-		}, {
-			.param = ISCSI_PARAM_PING_TMO,
-			.value = &conn->noop_out_timeout,
-			.type = ISCSI_INT,
-			.conn_only = 1,
-		}, {
-			.param = ISCSI_PARAM_RECV_TMO,
-			.value = &conn->noop_out_interval,
-			.type = ISCSI_INT,
-			.conn_only = 1,
-		}, {
-			.param = ISCSI_PARAM_IFACE_NAME,
-			.value = session->nrec.iface.name,
-			.type = ISCSI_STRING,
-		}, {
-			.param = ISCSI_PARAM_INITIATOR_NAME,
-			.value = session->initiator_name,
-			.type = ISCSI_STRING,
-		},
-	};
+	int rc;
 
 	actor_delete(&conn->login_timer);
-	/* Entered full-feature phase! */
-	for (i = 0; i < MAX_SESSION_PARAMS; i++) {
-		if (conn->id != 0 && !conntbl[i].conn_only)
-			continue;
-		
-		if (!(session->param_mask & (1ULL << conntbl[i].param)))
-			continue;
-
-		rc = ipc->set_param(session->t->handle, session->id,
-				   conn->id, conntbl[i].param, conntbl[i].value,
-				   conntbl[i].type);
-		if (rc && rc != -ENOSYS) {
-			log_error("can't set operational parameter %d for "
-				  "connection %d:%d, retcode %d (%d)",
-				  conntbl[i].param, session->id, conn->id,
-				  rc, errno);
-
-			iscsi_login_eh(conn, c->qtask,
-				       MGMT_IPC_ERR_LOGIN_FAILURE);
-			return;
-		}
-
-		if (rc == -ENOSYS) {
-			switch (conntbl[i].param) {
-			case ISCSI_PARAM_PING_TMO:
-				/*
-				 * older kernels may not support nops
-				 * in kernel
-				 */
-				conn->userspace_nop = 1;
-				break;
-			case ISCSI_PARAM_INITIATOR_NAME:
-				/* use host level one instead */
-				hosttbl[ISCSI_HOST_PARAM_INITIATOR_NAME].set = 1;
-				break;
-			}
-		}
 
-		print_param_value(conntbl[i].param, conntbl[i].value,
-				  conntbl[i].type);
+	if (iscsi_session_set_params(conn)) {
+		iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
+		return;
 	}
 
-	for (i = 0; i < MAX_HOST_PARAMS; i++) {
-		if (!hosttbl[i].set)
-			continue;
-
-		if (__iscsi_host_set_param(session->t, session->hostno,
-					   hosttbl[i].param, hosttbl[i].value,
-					   hosttbl[i].type)) {
-			iscsi_login_eh(conn, c->qtask,
-				       MGMT_IPC_ERR_LOGIN_FAILURE);
-			return;
-		}
-
-		print_param_value(hosttbl[i].param, hosttbl[i].value,
-				  hosttbl[i].type);
+	if (iscsi_host_set_params(session)) {
+		iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
+		return;
 	}
 
 	if (ipc->start_conn(session->t->handle, session->id, conn->id,
 			    &rc) || rc) {
 		log_error("can't start connection %d:%d retcode %d (%d)",
 			  session->id, conn->id, rc, errno);
-		iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_INTERNAL);
+		iscsi_login_eh(conn, c->qtask, ISCSI_ERR_INTERNAL);
 		return;
 	}
 
-	conn->state = STATE_LOGGED_IN;
+	conn->state = ISCSI_CONN_STATE_LOGGED_IN;
 	if (session->r_stage == R_STAGE_NO_CHANGE ||
 	    session->r_stage == R_STAGE_SESSION_REDIRECT) {
 		/*
@@ -1501,10 +1044,10 @@ setup_full_feature_phase(iscsi_conn_t *c
 			    session->nrec.conn[conn->id].port,
 			    session->nrec.iface.name);
 	} else {
-		session->sync_qtask = NULL;
+		session->notify_qtask = NULL;
 
 		session_online_devs(session->hostno, session->id);
-		mgmt_ipc_write_rsp(c->qtask, MGMT_IPC_OK);
+		mgmt_ipc_write_rsp(c->qtask, ISCSI_SUCCESS);
 		log_warning("connection%d:%d is operational after recovery "
 			    "(%d attempts)", session->id, conn->id,
 			     session->reopen_cnt);
@@ -1527,12 +1070,12 @@ setup_full_feature_phase(iscsi_conn_t *c
 
 static void iscsi_logout_timedout(void *data)
 {
-	struct iscsi_conn_context *conn_context = data;
-	struct iscsi_conn *conn = conn_context->conn;
+	struct iscsi_ev_context *ev_context = data;
+	struct iscsi_conn *conn = ev_context->conn;
 
-	iscsi_conn_context_put(conn_context); 
+	iscsi_ev_context_put(ev_context);
 	/*
-	 * assume we were in STATE_IN_LOGOUT or there
+	 * assume we were in ISCSI_CONN_STATE_IN_LOGOUT or there
 	 * was some nasty error
 	 */
 	log_debug(3, "logout timeout, dropping conn...\n");
@@ -1542,9 +1085,9 @@ static void iscsi_logout_timedout(void *
 static int iscsi_send_logout(iscsi_conn_t *conn)
 {
 	struct iscsi_logout hdr;
-	struct iscsi_conn_context *conn_context;
+	struct iscsi_ev_context *ev_context;
 
-	if (conn->state != STATE_LOGGED_IN)
+	if (conn->state != ISCSI_CONN_STATE_LOGGED_IN)
 		return EINVAL;
 
 	memset(&hdr, 0, sizeof(struct iscsi_logout));
@@ -1556,14 +1099,14 @@ static int iscsi_send_logout(iscsi_conn_
 	if (!iscsi_io_send_pdu(conn, (struct iscsi_hdr*)&hdr,
 			       ISCSI_DIGEST_NONE, NULL, ISCSI_DIGEST_NONE, 0))
 		return EIO;
-	conn->state = STATE_IN_LOGOUT;
+	conn->state = ISCSI_CONN_STATE_IN_LOGOUT;
 
-	conn_context = iscsi_conn_context_get(conn, 0);
-	if (!conn_context)
+	ev_context = iscsi_ev_context_get(conn, 0);
+	if (!ev_context)
 		/* unbounded logout */
 		log_warning("Could not allocate conn context for logout.");
 	else {
-		iscsi_sched_conn_context(conn_context, conn,
+		iscsi_sched_ev_context(ev_context, conn,
 					 conn->logout_timeout,
 					 EV_CONN_LOGOUT_TIMER);
 		log_debug(3, "logout timeout timer %u\n",
@@ -1575,16 +1118,18 @@ static int iscsi_send_logout(iscsi_conn_
 
 static void iscsi_stop(void *data)
 {
-	struct iscsi_conn_context *conn_context = data;
-	struct iscsi_conn *conn = conn_context->conn;
+	struct iscsi_ev_context *ev_context = data;
+	struct iscsi_conn *conn = ev_context->conn;
 	int rc = 0;
 
-	iscsi_conn_context_put(conn_context);
+	iscsi_ev_context_put(ev_context);
 
-	if (!iscsi_send_logout(conn))
-		return;
+	if (!(conn->session->t->caps & CAP_LOGIN_OFFLOAD)) {
+		if (!iscsi_send_logout(conn))
+			return;
+	}
 
-	rc = session_conn_shutdown(conn, conn->logout_qtask, MGMT_IPC_OK);
+	rc = session_conn_shutdown(conn, conn->logout_qtask, ISCSI_SUCCESS);
 	if (rc)
 		log_error("BUG: Could not shutdown session.");
 }
@@ -1683,6 +1228,7 @@ static void iscsi_recv_login_rsp(struct 
 { 
 	struct iscsi_session *session = conn->session;
 	iscsi_login_context_t *c = &conn->login_context;
+	int err = ISCSI_ERR_FATAL_LOGIN;
 
 	if (iscsi_login_rsp(session, c)) {
 		log_debug(1, "login_rsp ret (%d)", c->ret);
@@ -1703,6 +1249,9 @@ static void iscsi_recv_login_rsp(struct 
 		switch (__check_iscsi_status_class(session, conn->id,
 						   c->status_class,
 						   c->status_detail)) {
+		case CONN_LOGIN_AUTH_FAILED:
+			err = ISCSI_ERR_LOGIN_AUTH_FAILED;
+			goto failed;
 		case CONN_LOGIN_FAILED:
 			goto failed;
 		case CONN_LOGIN_IMM_REDIRECT_RETRY:
@@ -1718,10 +1267,9 @@ static void iscsi_recv_login_rsp(struct 
 
 	if (conn->current_stage != ISCSI_FULL_FEATURE_PHASE) {
 		/* more nego. needed! */
-		conn->state = STATE_IN_LOGIN;
+		conn->state = ISCSI_CONN_STATE_IN_LOGIN;
 		if (iscsi_login_req(session, c)) {
-			iscsi_login_eh(conn, c->qtask,
-				       MGMT_IPC_ERR_LOGIN_FAILURE);
+			iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
 			return;
 		}
 	} else
@@ -1730,36 +1278,35 @@ static void iscsi_recv_login_rsp(struct 
 	return;
 retry:
 	/* retry if not initial login or initial login has not timed out */
-	iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_LOGIN_FAILURE);
+	iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
 	return;
 failed:
 	/* force failure if initial login */
 	session->reopen_cnt = session->nrec.session.initial_login_retry_max;
-	iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_FATAL_LOGIN_FAILURE);
+	iscsi_login_eh(conn, c->qtask, err);
 	return;
 }
 
 static void session_conn_recv_pdu(void *data)
 {
-	struct iscsi_conn_context *conn_context = data;
-	iscsi_conn_t *conn = conn_context->conn;
+	struct iscsi_ev_context *ev_context = data;
+	iscsi_conn_t *conn = ev_context->conn;
 	struct iscsi_hdr hdr;
 
-	conn->recv_context = conn_context;
+	conn->recv_context = ev_context;
 
 	switch (conn->state) {
-	case STATE_IN_LOGIN:
+	case ISCSI_CONN_STATE_IN_LOGIN:
 		iscsi_recv_login_rsp(conn);
 		break;
-	case STATE_LOGGED_IN:
-	case STATE_IN_LOGOUT:
-	case STATE_LOGOUT_REQUESTED:
+	case ISCSI_CONN_STATE_LOGGED_IN:
+	case ISCSI_CONN_STATE_IN_LOGOUT:
+	case ISCSI_CONN_STATE_LOGOUT_REQUESTED:
 		/* read incoming PDU */
-		if (!iscsi_io_recv_pdu(conn, &hdr, ISCSI_DIGEST_NONE,
-			    conn->data, ISCSI_DEF_MAX_RECV_SEG_LEN,
-			    ISCSI_DIGEST_NONE, 0)) {
+		if (iscsi_io_recv_pdu(conn, &hdr, ISCSI_DIGEST_NONE,
+				      conn->data, ISCSI_DEF_MAX_RECV_SEG_LEN,
+				      ISCSI_DIGEST_NONE, 0) < 0)
 			return;
-		}
 
 		switch (hdr.opcode & ISCSI_OPCODE_MASK) {
 		case ISCSI_OP_NOOP_IN:
@@ -1776,18 +1323,18 @@ static void session_conn_recv_pdu(void *
 			break;
 		}
 		break;
-	case STATE_XPT_WAIT:
-		iscsi_conn_context_put(conn_context);
+	case ISCSI_CONN_STATE_XPT_WAIT:
+		iscsi_ev_context_put(ev_context);
 		log_debug(1, "ignoring incoming PDU in XPT_WAIT. "
 			  "let connection re-establish or fail");
 		break;
-	case STATE_CLEANUP_WAIT:
-		iscsi_conn_context_put(conn_context);
+	case ISCSI_CONN_STATE_CLEANUP_WAIT:
+		iscsi_ev_context_put(ev_context);
 		log_debug(1, "ignoring incoming PDU in XPT_WAIT. "
 			  "let connection cleanup");
 		break;
 	default:
-		iscsi_conn_context_put(conn_context);
+		iscsi_ev_context_put(ev_context);
 		log_error("Invalid state. Dropping PDU.\n");
 	}
 }
@@ -1908,35 +1455,66 @@ retry_create:
 	return err;
 }
 
+static void setup_offload_login_phase(iscsi_conn_t *conn)
+{
+	iscsi_session_t *session = conn->session;
+	iscsi_login_context_t *c = &conn->login_context;
+	int rc;
+
+	actor_delete(&conn->login_timer);
+
+	if (iscsi_session_set_params(conn)) {
+		iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
+		return;
+	}
+
+	if (iscsi_host_set_params(session)) {
+		iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
+		return;
+	}
+
+	conn->state = ISCSI_CONN_STATE_IN_LOGIN;
+	if (ipc->start_conn(session->t->handle, session->id, conn->id,
+			    &rc) || rc) {
+		log_error("can't start connection %d:%d retcode %d (%d)",
+			  session->id, conn->id, rc, errno);
+		iscsi_login_eh(conn, c->qtask, ISCSI_ERR_INTERNAL);
+		return;
+	}
+
+	session->notify_qtask = c->qtask;
+}
+
+
 static void session_conn_poll(void *data)
 {
-	struct iscsi_conn_context *conn_context = data;
-	iscsi_conn_t *conn = conn_context->conn;
+	struct iscsi_ev_context *ev_context = data;
+	iscsi_conn_t *conn = ev_context->conn;
 	struct iscsi_session *session = conn->session;
-	mgmt_ipc_err_e err = MGMT_IPC_OK;
-	queue_task_t *qtask = conn_context->data;
+	int err = ISCSI_SUCCESS;
+	queue_task_t *qtask = ev_context->data;
 	iscsi_login_context_t *c = &conn->login_context;
 	int rc;
 
-	iscsi_conn_context_put(conn_context);
+	iscsi_ev_context_put(ev_context);
 
-	if (conn->state != STATE_XPT_WAIT)
+	if (conn->state != ISCSI_CONN_STATE_XPT_WAIT)
 		return;
 
 	rc = session->t->template->ep_poll(conn, 1);
 	if (rc == 0) {
 		log_debug(4, "poll not connected %d", rc);
 		/* timedout: Poll again. */
-		conn_context = iscsi_conn_context_get(conn, 0);
-		if (!conn_context) {
+		ev_context = iscsi_ev_context_get(conn, 0);
+		if (!ev_context) {
 			/* while polling the recv pool should be full */
 			log_error("BUG: session_conn_poll could not get conn "
 				  "context.");
-			iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_INTERNAL);
+			iscsi_login_eh(conn, qtask, ISCSI_ERR_INTERNAL);
 			return;
 		}
-		conn_context->data = qtask;
-		iscsi_sched_conn_context(conn_context, conn, 0, EV_CONN_POLL);
+		ev_context->data = qtask;
+		iscsi_sched_ev_context(ev_context, conn, 0, EV_CONN_POLL);
 	} else if (rc > 0) {
 		/* connected! */
 		memset(c, 0, sizeof(iscsi_login_context_t));
@@ -1945,26 +1523,26 @@ static void session_conn_poll(void *data
 		if (session->id == -1) {
 			if (conn->id == 0 && session_ipc_create(session)) {
 				log_error("Can't create session.");
-				err = MGMT_IPC_ERR_INTERNAL;
+				err = ISCSI_ERR_INTERNAL;
 				goto cleanup;
 			}
 			log_debug(3, "created new iSCSI session sid %d host "
 				  "no %u", session->id, session->hostno);
 
-			if (ipc->create_conn(session->t->handle,
-					session->id, conn->id, &conn->id)) {
+			err = ipc->create_conn(session->t->handle,
+					session->id, conn->id, &conn->id);
+			if (err) {
 				log_error("Can't create connection.");
-				err = MGMT_IPC_ERR_INTERNAL;
+				err = ISCSI_ERR_INTERNAL;
 				goto cleanup;
 			}
 			log_debug(3, "created new iSCSI connection "
 				  "%d:%d", session->id, conn->id);
 		}
 
-		iscsi_copy_operational_params(conn);
-
-		if (session->t->template->create_conn)
-			session->t->template->create_conn(conn);
+		iscsi_copy_operational_params(conn,
+					&session->nrec.session.iscsi,
+					&session->nrec.conn[conn->id].iscsi);
 		/*
 		 * TODO: use the iface number or some other value
 		 * so this will be persistent
@@ -1977,7 +1555,7 @@ static void session_conn_poll(void *data
 			log_error("can't bind conn %d:%d to session %d, "
 				  "retcode %d (%d)", session->id, conn->id,
 				   session->id, rc, errno);
-			iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_LOGIN_FAILURE);
+			iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN);
 			return;
 		}
 		log_debug(3, "bound iSCSI connection %d:%d to session %d",
@@ -1990,14 +1568,19 @@ static void session_conn_poll(void *data
 
 		conn->exp_statsn = iscsi_sysfs_get_exp_statsn(session->id);
 
+		if (session->t->caps & CAP_LOGIN_OFFLOAD) {
+			setup_offload_login_phase(conn);
+			return;
+		}
+
 		if (iscsi_login_begin(session, c)) {
-			iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_LOGIN_FAILURE);
+			iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN);
 			return;
 		}
 
-		conn->state = STATE_IN_LOGIN;
+		conn->state = ISCSI_CONN_STATE_IN_LOGIN;
 		if (iscsi_login_req(session, c)) {
-			iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_LOGIN_FAILURE);
+			iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN);
 			return;
 		}
 	} else {
@@ -2011,70 +1594,125 @@ cleanup:
 	session_conn_shutdown(conn, qtask, err);
 }
 
-void iscsi_sched_conn_context(struct iscsi_conn_context *conn_context,
-			      struct iscsi_conn *conn, unsigned long tmo,
-			      int event)
+static void session_conn_process_login(void *data)
+{
+	struct iscsi_ev_context *ev_context = data;
+	enum iscsi_conn_state state = *(enum iscsi_conn_state *)
+							ev_context->data;
+	struct iscsi_conn *conn = ev_context->conn;
+	struct iscsi_session *session = conn->session;
+	iscsi_login_context_t *c = &conn->login_context;
+	queue_task_t *qtask;
+
+	iscsi_ev_context_put(ev_context);
+	if (!(session->t->caps & CAP_LOGIN_OFFLOAD))
+		return;
+
+	if (state == ISCSI_CONN_STATE_FREE)
+		goto failed_login;
+
+	conn->state = ISCSI_CONN_STATE_LOGGED_IN;
+	/*
+	 * ok we were in_login and now we got the notification that we are
+	 * logged in
+	 */
+	log_debug(3, "session created sid %u host no %d", session->id,
+		  session->hostno);
+
+	if (session->r_stage == R_STAGE_NO_CHANGE ||
+	    session->r_stage == R_STAGE_SESSION_REDIRECT) {
+		/*
+		 * scan host is one-time deal. We
+		 * don't want to re-scan it on recovery.
+		 */
+		session_scan_host(session, session->hostno,
+				 c->qtask);
+		session->notify_qtask = NULL;
+
+		log_warning("Connection%d:%d to [target: %s, portal: %s,%d] "
+			    "through [iface: %s] is operational now",
+			    session->id, conn->id, session->nrec.name,
+			    session->nrec.conn[conn->id].address,
+			    session->nrec.conn[conn->id].port,
+			    session->nrec.iface.name);
+	} else
+		session->notify_qtask = NULL;
+
+
+	/*
+	 * reset ERL=0 reopen counter
+	 */
+	session->reopen_cnt = 0;
+	session->r_stage = R_STAGE_NO_CHANGE;
+
+	return;
+
+failed_login:
+	qtask = session->notify_qtask;
+	session->notify_qtask = NULL;
+	mgmt_ipc_write_rsp(qtask, ISCSI_ERR_LOGIN);
+	if (ipc->destroy_conn(session->t->handle, session->id, conn->id))
+		log_error("can not safely destroy connection %d", conn->id);
+	if (ipc->destroy_session(session->t->handle, session->id))
+		log_error("can not safely destroy session %d", session->id);
+	__session_destroy(session);
+
+}
+
+static int iscsi_sched_ev_context(struct iscsi_ev_context *ev_context,
+				  struct iscsi_conn *conn, unsigned long tmo,
+				  int event)
 {
 	enum iscsi_err error;
 
 	log_debug(7, "sched conn context %p event %d, tmo %lu",
-		  &conn_context->actor, event, tmo);
+		  &ev_context->actor, event, tmo);
 
-	conn_context->conn = conn;
+	ev_context->conn = conn;
 	switch (event) {
 	case EV_CONN_RECV_PDU:
-		actor_new(&conn_context->actor, session_conn_recv_pdu,
-			  conn_context);
-		actor_schedule(&conn_context->actor);
+		actor_new(&ev_context->actor, session_conn_recv_pdu,
+			  ev_context);
+		actor_schedule(&ev_context->actor);
 		break;
 	case EV_CONN_ERROR:
-		error = *(enum iscsi_err *)conn_context->data;
+		error = *(enum iscsi_err *)ev_context->data;
 
-		actor_new(&conn_context->actor, session_conn_error,
-			  conn_context);
+		actor_new(&ev_context->actor, session_conn_error,
+			  ev_context);
 		/*
 		 * We handle invalid host, by killing the session.
 		 * It must go at the head of the queue, so we do not
 		 * initiate error handling or logout or some other op.
 		 */
 		if (error == ISCSI_ERR_INVALID_HOST)
-			actor_schedule_head(&conn_context->actor);
+			actor_schedule_head(&ev_context->actor);
 		else
-			actor_schedule(&conn_context->actor);
+			actor_schedule(&ev_context->actor);
+		break;
+	case EV_CONN_LOGIN:
+		actor_new(&ev_context->actor, session_conn_process_login,
+			  ev_context);
+		actor_schedule(&ev_context->actor);
 		break;
 	case EV_CONN_POLL:
-		actor_new(&conn_context->actor, session_conn_poll,
-			  conn_context);
-		actor_schedule(&conn_context->actor);
+		actor_new(&ev_context->actor, session_conn_poll,
+			  ev_context);
+		actor_schedule(&ev_context->actor);
 		break;
 	case EV_CONN_LOGOUT_TIMER:
-		actor_timer(&conn_context->actor, tmo * 1000,
-			    iscsi_logout_timedout, conn_context);
+		actor_timer(&ev_context->actor, tmo * 1000,
+			    iscsi_logout_timedout, ev_context);
 		break;
 	case EV_CONN_STOP:
-		actor_new(&conn_context->actor, iscsi_stop,
-			  conn_context);
-		actor_schedule(&conn_context->actor);
+		actor_new(&ev_context->actor, iscsi_stop,
+			  ev_context);
+		actor_schedule(&ev_context->actor);
 		break;
 	default:
 		log_error("Invalid event type %d.", event);
-		return;
 	}
-}
-
-iscsi_session_t*
-session_find_by_sid(int sid)
-{
-	struct iscsi_transport *t;
-	iscsi_session_t *session;
-
-	list_for_each_entry(t, &transports, list) {
-		list_for_each_entry(session, &t->sessions, list) {
-			if (session->id == sid)
-				return session;
-		}
-	}
-	return NULL;
+	return 0;
 }
 
 static iscsi_session_t* session_find_by_rec(node_rec_t *rec)
@@ -2087,7 +1725,8 @@ static iscsi_session_t* session_find_by_
 			if (__iscsi_match_session(rec, session->nrec.name,
 					 session->nrec.conn[0].address,
 					 session->nrec.conn[0].port,
-					 &session->nrec.iface))
+					 &session->nrec.iface,
+					 MATCH_ANY_SID))
 				return session;
 		}
 	}
@@ -2111,65 +1750,24 @@ static int session_is_running(node_rec_t
 	return 0;
 }
 
-static int iface_set_param(struct iscsi_transport *t, struct iface_rec *iface,
-			   struct iscsi_session *session)
-{
-	int rc = 0;
-
-	log_debug(3, "setting iface %s, dev %s, set ip %s, hw %s, "
-		  "transport %s.\n",
-		  iface->name, iface->netdev, iface->ipaddress,
-		  iface->hwaddress, iface->transport_name);
-
-	if (!t->template->set_host_ip)
-		return 0;
-
-	/* if we need to set the ip addr then set all the iface net settings */
-	if (!iface_is_bound_by_ipaddr(iface)) {
-		log_warning("Please set the iface.ipaddress for iface %s, "
-			    "then retry the login command.\n", iface->name);
-		return EINVAL;
-	}
-
-	rc = __iscsi_host_set_param(t, session->hostno,
-				    ISCSI_HOST_PARAM_IPADDRESS,
-				    iface->ipaddress, ISCSI_STRING);
-	if (rc)
-		return rc;
-
-	if (iface_is_bound_by_netdev(iface)) {
-		rc = __iscsi_host_set_param(t, session->hostno,
-					    ISCSI_HOST_PARAM_NETDEV_NAME,
-					    iface->netdev, ISCSI_STRING);
-		if (rc)
-			return rc;
-	}
-
-	if (iface_is_bound_by_hwaddr(iface)) {
-		rc = __iscsi_host_set_param(t, session->hostno,
-					    ISCSI_HOST_PARAM_HWADDRESS,
-					    iface->hwaddress, ISCSI_STRING);
-		if (rc)
-			return rc;
-	}
-	return 0;
-}
-
 int
 session_login_task(node_rec_t *rec, queue_task_t *qtask)
 {
 	iscsi_session_t *session;
 	iscsi_conn_t *conn;
 	struct iscsi_transport *t;
+	int rc;
 
-	if (session_is_running(rec))
-		return MGMT_IPC_ERR_EXISTS;
+	if (session_is_running(rec)) {
+		if (rec->session.multiple)
+			log_debug(2, "Adding a copy of an existing session");
+		else
+			return ISCSI_ERR_SESS_EXISTS;
+	}
 
 	t = iscsi_sysfs_get_transport_by_name(rec->iface.transport_name);
 	if (!t)
-		return MGMT_IPC_ERR_TRANS_NOT_FOUND;
-	if (set_transport_template(t))
-		return MGMT_IPC_ERR_TRANS_NOT_FOUND;
+		return ISCSI_ERR_TRANS_NOT_FOUND;
 
 	if ((!(t->caps & CAP_RECOVERY_L0) &&
 	     rec->session.iscsi.ERL != 0) ||
@@ -2222,27 +1820,22 @@ session_login_task(node_rec_t *rec, queu
 
 	session = __session_create(rec, t);
 	if (!session)
-		return MGMT_IPC_ERR_LOGIN_FAILURE;
+		return ISCSI_ERR_LOGIN;
 
 	/* FIXME: login all connections! marked as "automatic" */
 
 	/* create leading connection */
-	if (__session_conn_create(session, 0)) {
+	rc = __session_conn_create(session, 0);
+	if (rc) {
 		__session_destroy(session);
-		return MGMT_IPC_ERR_LOGIN_FAILURE;
+		return rc;
 	}
 	conn = &session->conn[0];
 	qtask->conn = conn;
 
-	if (iface_set_param(t, &rec->iface, session)) {
+	if (iscsi_host_set_net_params(&rec->iface, session)) {
 		__session_destroy(session);
-		return MGMT_IPC_ERR_LOGIN_FAILURE;
-	}
-
-	conn->state = STATE_XPT_WAIT;
-	if (iscsi_conn_connect(conn, qtask)) {
-		__session_destroy(session);
-		return MGMT_IPC_ERR_TRANS_FAILURE;
+		return ISCSI_ERR_LOGIN;
 	}
 
 	if (gettimeofday(&conn->initial_connect_time, NULL))
@@ -2250,26 +1843,37 @@ session_login_task(node_rec_t *rec, queu
 			  "login errors iscsid may give up the initial "
 			  "login early. You should manually login.");
 
+	conn->state = ISCSI_CONN_STATE_XPT_WAIT;
 	qtask->rsp.command = MGMT_IPC_SESSION_LOGIN;
-	qtask->rsp.err = MGMT_IPC_OK;
-	return MGMT_IPC_OK;
+	qtask->rsp.err = ISCSI_SUCCESS;
+
+	if (iscsi_conn_connect(conn, qtask)) {
+		log_debug(4, "Initial connect failed. Waiting %u seconds "
+			  "before trying to reconnect.\n",
+			  ISCSI_CONN_ERR_REOPEN_DELAY);
+		queue_delayed_reopen(qtask, ISCSI_CONN_ERR_REOPEN_DELAY);
+	}
+
+	return ISCSI_SUCCESS;
 }
 
 static int
 sync_conn(iscsi_session_t *session, uint32_t cid)
 {
 	iscsi_conn_t *conn;
+	int rc;
 
-	if (__session_conn_create(session, cid))
-		return ENOMEM;
+	rc = __session_conn_create(session, cid);
+	if (rc)
+		return rc;
 	conn = &session->conn[cid];
 
 	/* TODO: must export via sysfs so we can pick this up */
-	conn->state = STATE_CLEANUP_WAIT;
+	conn->state = ISCSI_CONN_STATE_CLEANUP_WAIT;
 	return 0;
 }
 
-mgmt_ipc_err_e
+int
 iscsi_sync_session(node_rec_t *rec, queue_task_t *qtask, uint32_t sid)
 {
 	iscsi_session_t *session;
@@ -2278,38 +1882,32 @@ iscsi_sync_session(node_rec_t *rec, queu
 
 	t = iscsi_sysfs_get_transport_by_name(rec->iface.transport_name);
 	if (!t)
-		return MGMT_IPC_ERR_TRANS_NOT_FOUND;
-	if (set_transport_template(t))
-		return MGMT_IPC_ERR_TRANS_NOT_FOUND;
+		return ISCSI_ERR_TRANS_NOT_FOUND;
 
 	session = __session_create(rec, t);
 	if (!session)
-		return MGMT_IPC_ERR_LOGIN_FAILURE;
+		return ISCSI_ERR_LOGIN;
 
 	session->id = sid;
 	session->hostno = iscsi_sysfs_get_host_no_from_sid(sid, &err);
 	if (err) {
 		log_error("Could not get hostno for session %d\n", sid);
-		err = MGMT_IPC_ERR_NOT_FOUND;
 		goto destroy_session;
 	}
 
 	session->r_stage = R_STAGE_SESSION_REOPEN;
 
 	err = sync_conn(session, 0);
-	if (err) {
-		if (err == ENOMEM)
-			err = MGMT_IPC_ERR_NOMEM;
-		else
-			err = MGMT_IPC_ERR_INVAL;
+	if (err)
 		goto destroy_session;
-	}
 
-	session->sync_qtask = qtask;
 	qtask->rsp.command = MGMT_IPC_SESSION_SYNC;
 
-	session_conn_reopen(&session->conn[0], qtask, STOP_CONN_RECOVER);
 	log_debug(3, "Started sync iSCSI session %d", session->id);
+	session->notify_qtask = qtask;
+	session_conn_reopen(&session->conn[0], qtask,
+			    STOP_CONN_RECOVER);
+
 	return 0;
 
 destroy_session:
@@ -2329,37 +1927,35 @@ static int session_unbind(struct iscsi_s
 	return err;
 }
 
-int
-session_logout_task(int sid, queue_task_t *qtask)
+int session_logout_task(int sid, queue_task_t *qtask)
 {
 	iscsi_session_t *session;
 	iscsi_conn_t *conn;
-	mgmt_ipc_err_e rc = MGMT_IPC_OK;
+	int rc = ISCSI_SUCCESS;
 
 	session = session_find_by_sid(sid);
 	if (!session) {
                 log_debug(1, "session sid %d not found.\n", sid);
-		return MGMT_IPC_ERR_NOT_FOUND;
+		return ISCSI_ERR_SESS_NOT_FOUND;
 	}
 	conn = &session->conn[0];
 	/*
 	 * If syncing up or if this is the initial login and mgmt_ipc
 	 * has not been notified of that result fail the logout request
 	 */
-	if (session->sync_qtask ||
-	    ((conn->state == STATE_XPT_WAIT ||
-	      conn->state == STATE_IN_LOGIN) &&
+	if (session->notify_qtask ||
+	    ((conn->state == ISCSI_CONN_STATE_XPT_WAIT ||
+	      conn->state == ISCSI_CONN_STATE_IN_LOGIN) &&
 	    (session->r_stage == R_STAGE_NO_CHANGE ||
 	     session->r_stage == R_STAGE_SESSION_REDIRECT))) {
 invalid_state:
 		log_error("session in invalid state for logout. "
 			   "Try again later\n");
-		return MGMT_IPC_ERR_INTERNAL;
+		return ISCSI_ERR_INTERNAL;
 	}
 
 	/* FIXME: logout all active connections */
 	conn = &session->conn[0];
-	/* FIXME: implement Logout Request */
 	if (conn->logout_qtask)
 		goto invalid_state;
 
@@ -2368,41 +1964,45 @@ invalid_state:
 	conn->logout_qtask = qtask;
 
 	switch (conn->state) {
-	case STATE_LOGGED_IN:
+	case ISCSI_CONN_STATE_LOGGED_IN:
 		if (!session_unbind(session))
-			return MGMT_IPC_OK;
+			return ISCSI_SUCCESS;
+
+		/* LLDs that offload login also offload logout */
+		if (!(session->t->caps & CAP_LOGIN_OFFLOAD)) {
+			/* unbind is not supported so just do old logout */
+			if (!iscsi_send_logout(conn))
+				return ISCSI_SUCCESS;
+		}
 
-		/* unbind is not supported so just do old logout */
-		if (!iscsi_send_logout(conn))
-			return MGMT_IPC_OK;
 		log_error("Could not send logout pdu. Dropping session\n");
 		/* fallthrough */
 	default:
-		rc = session_conn_shutdown(conn, qtask, MGMT_IPC_OK);
+		rc = session_conn_shutdown(conn, qtask, ISCSI_SUCCESS);
 		break;
 	}
 
 	return rc;
 }
 
-mgmt_ipc_err_e
+int
 iscsi_host_send_targets(queue_task_t *qtask, int host_no, int do_login,
 			struct sockaddr_storage *ss)
 {
 	struct iscsi_transport *t;
 
 	t = iscsi_sysfs_get_transport_by_hba(host_no);
-	if (!t || set_transport_template(t)) {
+	if (!t) {
 		log_error("Invalid host no %d for sendtargets\n", host_no);
-		return MGMT_IPC_ERR_TRANS_FAILURE;
+		return ISCSI_ERR_TRANS_NOT_FOUND;
 	}
 	if (!(t->caps & CAP_SENDTARGETS_OFFLOAD))
-		return MGMT_IPC_ERR_TRANS_CAPS;
+		return ISCSI_ERR_TRANS_CAPS;
 
 	if (ipc->sendtargets(t->handle, host_no, (struct sockaddr *)ss))
-		return MGMT_IPC_ERR;
+		return ISCSI_ERR;
 
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
 /*
@@ -2412,7 +2012,7 @@ iscsi_host_send_targets(queue_task_t *qt
  * the card will have sessions preset in the FLASH and will log into them
  * automaotically then send us notification that a session is setup.
  */
-void iscsi_async_session_creation(uint32_t host_no, uint32_t sid)
+static void iscsi_async_session_creation(uint32_t host_no, uint32_t sid)
 {
 	struct iscsi_transport *transport;
 
@@ -2428,7 +2028,20 @@ void iscsi_async_session_creation(uint32
 	session_scan_host(NULL, host_no, NULL);
 }
 
-void iscsi_async_session_destruction(uint32_t host_no, uint32_t sid)
+static void iscsi_async_session_destruction(uint32_t host_no, uint32_t sid)
 {
 	log_debug(3, "session destroyed sid %u host no %d", sid, host_no);
 }
+
+static struct iscsi_ipc_ev_clbk ipc_clbk = {
+	.create_session		= iscsi_async_session_creation,
+	.destroy_session	= iscsi_async_session_destruction,
+	.get_ev_context		= iscsi_ev_context_get,
+	.put_ev_context		= iscsi_ev_context_put,
+	.sched_ev_context	= iscsi_sched_ev_context,
+};
+
+void iscsi_initiator_init(void)
+{
+	ipc_register_ev_callback(&ipc_clbk);
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/initiator_common.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/initiator_common.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/initiator_common.c	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/initiator_common.c	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,607 @@
+/*
+ * Common code for setting up discovery and normal sessions.
+ *
+ * Copyright (C) 2004 Dmitry Yusupov, Alex Aizman
+ * Copyright (C) 2006 - 2009 Mike Christie
+ * Copyright (C) 2006 - 2009 Red Hat, Inc. All rights reserved.
+ * maintained by open-iscsi@googlegroups.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * See the file COPYING included with this distribution for more details.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "initiator.h"
+#include "transport.h"
+#include "iscsid.h"
+#include "iscsi_ipc.h"
+#include "log.h"
+#include "iscsi_sysfs.h"
+#include "iscsi_settings.h"
+#include "iface.h"
+#include "host.h"
+#include "sysdeps.h"
+#include "iscsi_err.h"
+
+struct iscsi_session *session_find_by_sid(uint32_t sid)
+{
+	struct iscsi_transport *t;
+	struct iscsi_session *session;
+
+	list_for_each_entry(t, &transports, list) {
+		list_for_each_entry(session, &t->sessions, list) {
+			if (session->id == sid)
+				return session;
+		}
+	}
+	return NULL;
+}
+
+/*
+ * calculate parameter's padding
+ */
+static unsigned int
+__padding(unsigned int param)
+{
+	int pad;
+
+	pad = param & 3;
+	if (pad) {
+		pad = 4 - pad;
+		log_debug(1, "parameter's value %d padded to %d bytes\n",
+			   param, param + pad);
+	}
+	return param + pad;
+}
+
+int iscsi_setup_authentication(struct iscsi_session *session,
+			       struct iscsi_auth_config *auth_cfg)
+{
+	/* if we have any incoming credentials, we insist on authenticating
+	 * the target or not logging in at all
+	 */
+	if (auth_cfg->username_in[0] || auth_cfg->password_in_length) {
+		/* sanity check the config */
+		if (auth_cfg->password_length == 0) {
+			log_warning("CHAP configuratoin has incoming "
+				    "authentication credentials but has no "
+				    "outgoing credentials configured.");
+			return EINVAL;
+		}
+		session->bidirectional_auth = 1;
+	} else {
+		/* no or 1-way authentication */
+		session->bidirectional_auth = 0;
+	}
+
+	/* copy in whatever credentials we have */
+	strlcpy(session->username, auth_cfg->username,
+		sizeof (session->username));
+	session->username[sizeof (session->username) - 1] = '\0';
+	if ((session->password_length = auth_cfg->password_length))
+		memcpy(session->password, auth_cfg->password,
+		       session->password_length);
+
+	strlcpy(session->username_in, auth_cfg->username_in,
+		sizeof (session->username_in));
+	session->username_in[sizeof (session->username_in) - 1] = '\0';
+	if ((session->password_in_length =
+	     auth_cfg->password_in_length))
+		memcpy(session->password_in, auth_cfg->password_in,
+		       session->password_in_length);
+
+	if (session->password_length || session->password_in_length) {
+		/* setup the auth buffers */
+		session->auth_buffers[0].address = &session->auth_client_block;
+		session->auth_buffers[0].length =
+		    sizeof (session->auth_client_block);
+		session->auth_buffers[1].address =
+		    &session->auth_recv_string_block;
+		session->auth_buffers[1].length =
+		    sizeof (session->auth_recv_string_block);
+
+		session->auth_buffers[2].address =
+		    &session->auth_send_string_block;
+		session->auth_buffers[2].length =
+		    sizeof (session->auth_send_string_block);
+
+		session->auth_buffers[3].address =
+		    &session->auth_recv_binary_block;
+		session->auth_buffers[3].length =
+		    sizeof (session->auth_recv_binary_block);
+
+		session->auth_buffers[4].address =
+		    &session->auth_send_binary_block;
+		session->auth_buffers[4].length =
+		    sizeof (session->auth_send_binary_block);
+
+		session->num_auth_buffers = 5;
+		log_debug(6, "authentication setup complete...");
+	} else {
+		session->num_auth_buffers = 0;
+		log_debug(6, "no authentication configured...");
+	}
+
+	return 0;
+}
+
+void
+iscsi_copy_operational_params(struct iscsi_conn *conn,
+			struct iscsi_session_operational_config *session_conf,
+			struct iscsi_conn_operational_config *conn_conf)
+{
+	struct iscsi_session *session = conn->session;
+	struct iscsi_transport *t = session->t;
+
+	conn->hdrdgst_en = conn_conf->HeaderDigest;
+	conn->datadgst_en = conn_conf->DataDigest;
+
+	conn->max_recv_dlength =
+			__padding(conn_conf->MaxRecvDataSegmentLength);
+	if (conn->max_recv_dlength < ISCSI_MIN_MAX_RECV_SEG_LEN ||
+	    conn->max_recv_dlength > ISCSI_MAX_MAX_RECV_SEG_LEN) {
+		log_error("Invalid iscsi.MaxRecvDataSegmentLength. Must be "
+			 "within %u and %u. Setting to %u\n",
+			  ISCSI_MIN_MAX_RECV_SEG_LEN,
+			  ISCSI_MAX_MAX_RECV_SEG_LEN,
+			  DEF_INI_MAX_RECV_SEG_LEN);
+		conn_conf->MaxRecvDataSegmentLength =
+						DEF_INI_MAX_RECV_SEG_LEN;
+		conn->max_recv_dlength = DEF_INI_MAX_RECV_SEG_LEN;
+	}
+
+	/* zero indicates to use the target's value */
+	conn->max_xmit_dlength =
+			__padding(conn_conf->MaxXmitDataSegmentLength);
+	if (conn->max_xmit_dlength == 0)
+		conn->max_xmit_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN;
+	if (conn->max_xmit_dlength < ISCSI_MIN_MAX_RECV_SEG_LEN ||
+	    conn->max_xmit_dlength > ISCSI_MAX_MAX_RECV_SEG_LEN) {
+		log_error("Invalid iscsi.MaxXmitDataSegmentLength. Must be "
+			 "within %u and %u. Setting to %u\n",
+			  ISCSI_MIN_MAX_RECV_SEG_LEN,
+			  ISCSI_MAX_MAX_RECV_SEG_LEN,
+			  DEF_INI_MAX_RECV_SEG_LEN);
+		conn_conf->MaxXmitDataSegmentLength =
+						DEF_INI_MAX_RECV_SEG_LEN;
+		conn->max_xmit_dlength = DEF_INI_MAX_RECV_SEG_LEN;
+	}
+
+	/* session's operational parameters */
+	session->initial_r2t_en = session_conf->InitialR2T;
+	session->imm_data_en = session_conf->ImmediateData;
+	session->first_burst = __padding(session_conf->FirstBurstLength);
+	/*
+	 * some targets like netapp fail the login if sent bad first_burst
+	 * and max_burst lens, even when immediate data=no and
+	 * initial r2t = Yes, so we always check the user values.
+	 */
+	if (session->first_burst < ISCSI_MIN_FIRST_BURST_LEN ||
+	    session->first_burst > ISCSI_MAX_FIRST_BURST_LEN) {
+		log_error("Invalid iscsi.FirstBurstLength of %u. Must be "
+			 "within %u and %u. Setting to %u\n",
+			  session->first_burst,
+			  ISCSI_MIN_FIRST_BURST_LEN,
+			  ISCSI_MAX_FIRST_BURST_LEN,
+			  DEF_INI_FIRST_BURST_LEN);
+		session_conf->FirstBurstLength = DEF_INI_FIRST_BURST_LEN;
+		session->first_burst = DEF_INI_FIRST_BURST_LEN;
+	}
+
+	session->max_burst = __padding(session_conf->MaxBurstLength);
+	if (session->max_burst < ISCSI_MIN_MAX_BURST_LEN ||
+	    session->max_burst > ISCSI_MAX_MAX_BURST_LEN) {
+		log_error("Invalid iscsi.MaxBurstLength of %u. Must be "
+			  "within %u and %u. Setting to %u\n",
+			   session->max_burst, ISCSI_MIN_MAX_BURST_LEN,
+			   ISCSI_MAX_MAX_BURST_LEN, DEF_INI_MAX_BURST_LEN);
+		session_conf->MaxBurstLength = DEF_INI_MAX_BURST_LEN;
+		session->max_burst = DEF_INI_MAX_BURST_LEN;
+	}
+
+	if (session->first_burst > session->max_burst) {
+		log_error("Invalid iscsi.FirstBurstLength of %u. Must be "
+			  "less than iscsi.MaxBurstLength. Setting to %u\n",
+			   session->first_burst, session->max_burst);
+		session_conf->FirstBurstLength = session->max_burst;
+		session->first_burst = session->max_burst;
+	}
+
+	session->def_time2wait = session_conf->DefaultTime2Wait;
+	session->def_time2retain = session_conf->DefaultTime2Retain;
+	session->erl = session_conf->ERL;
+
+	if (session->type == ISCSI_SESSION_TYPE_DISCOVERY) {
+		/*
+		 * Right now, we only support 8K max for kernel based
+		 * sendtargets discovery, because the recv pdu buffers are
+		 * limited to this size.
+		 */
+		if ((t->caps & CAP_TEXT_NEGO) &&
+		     conn->max_recv_dlength > ISCSI_DEF_MAX_RECV_SEG_LEN)
+			conn->max_recv_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN;
+
+		/* We do not support discovery sessions with digests */
+		conn->hdrdgst_en = ISCSI_DIGEST_NONE;
+		conn->datadgst_en = ISCSI_DIGEST_NONE;
+	}
+
+	if (t->template->create_conn)
+		t->template->create_conn(conn);
+}
+
+int iscsi_setup_portal(struct iscsi_conn *conn, char *address, int port)
+{
+	char serv[NI_MAXSERV];
+
+	sprintf(serv, "%d", port);
+	if (resolve_address(address, serv, &conn->saddr)) {
+		log_error("cannot resolve host name %s", address);
+		return ISCSI_ERR_TRANS;
+	}
+	conn->failback_saddr = conn->saddr;
+
+	getnameinfo((struct sockaddr *)&conn->saddr, sizeof(conn->saddr),
+		    conn->host, sizeof(conn->host), NULL, 0, NI_NUMERICHOST);
+	log_debug(4, "resolved %s to %s", address, conn->host);
+	return 0;
+}
+
+int host_set_param(struct iscsi_transport *t,
+		   uint32_t host_no, int param, char *value,
+		   int type)
+{
+	int rc;
+
+	rc = ipc->set_host_param(t->handle, host_no, param, value, type);
+	/* 2.6.20 and below returns EINVAL */
+	if (rc && rc != -ENOSYS && rc != -EINVAL) {
+		log_error("can't set operational parameter %d for "
+			  "host %d, retcode %d (%d)", param, host_no,
+			  rc, errno);
+		return rc;
+	}
+	return 0;
+}
+
+static void print_param_value(enum iscsi_param param, void *value, int type)
+{
+	log_debug(3, "set operational parameter %d to:", param);
+
+	if (type == ISCSI_STRING)
+		log_debug(3, "%s", value ? (char *)value : "NULL");
+	else
+		log_debug(3, "%u", *(uint32_t *)value);
+}
+
+#define MAX_HOST_PARAMS 2
+
+int iscsi_host_set_params(struct iscsi_session *session)
+{
+	struct iscsi_transport *t = session->t;
+	int i;
+	struct hostparam {
+		int param;
+		int type;
+		void *value;
+	} hosttbl[MAX_HOST_PARAMS] = {
+		{
+			.param = ISCSI_HOST_PARAM_NETDEV_NAME,
+			.value = session->nrec.iface.netdev,
+			.type = ISCSI_STRING,
+		}, {
+			.param = ISCSI_HOST_PARAM_HWADDRESS,
+			.value = session->nrec.iface.hwaddress,
+			.type = ISCSI_STRING,
+		},
+	};
+
+	for (i = 0; i < MAX_HOST_PARAMS; i++) {
+		if (host_set_param(t, session->hostno,
+				   hosttbl[i].param, hosttbl[i].value,
+				   hosttbl[i].type)) {
+			return EPERM;
+		}
+
+		print_param_value(hosttbl[i].param, hosttbl[i].value,
+				  hosttbl[i].type);
+	}
+
+	return 0;
+}
+
+#define MAX_SESSION_PARAMS 32
+
+int iscsi_session_set_params(struct iscsi_conn *conn)
+{
+	struct iscsi_session *session = conn->session;
+	struct iscsi_transport *t = session->t;
+	int i, rc;
+	uint32_t one = 1, zero = 0;
+	struct connparam {
+		int param;
+		int type;
+		void *value;
+		int conn_only;
+	} conntbl[MAX_SESSION_PARAMS] = {
+		{
+			.param = ISCSI_PARAM_MAX_RECV_DLENGTH,
+			.value = &conn->max_recv_dlength,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_MAX_XMIT_DLENGTH,
+			.value = &conn->max_xmit_dlength,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_HDRDGST_EN,
+			.value = &conn->hdrdgst_en,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_DATADGST_EN,
+			.value = &conn->datadgst_en,
+			.type = ISCSI_INT,
+			.conn_only = 1,
+		}, {
+			.param = ISCSI_PARAM_INITIAL_R2T_EN,
+			.value = &session->initial_r2t_en,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_MAX_R2T,
+			.value = &one, /* FIXME: session->max_r2t */
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_IMM_DATA_EN,
+			.value = &session->imm_data_en,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_FIRST_BURST,
+			.value = &session->first_burst,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_MAX_BURST,
+			.value = &session->max_burst,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_PDU_INORDER_EN,
+			.value = &session->pdu_inorder_en,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param =ISCSI_PARAM_DATASEQ_INORDER_EN,
+			.value = &session->dataseq_inorder_en,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_ERL,
+			.value = &zero, /* FIXME: session->erl */
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_IFMARKER_EN,
+			.value = &zero,/* FIXME: session->ifmarker_en */
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_OFMARKER_EN,
+			.value = &zero,/* FIXME: session->ofmarker_en */
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_EXP_STATSN,
+			.value = &conn->exp_statsn,
+			.type = ISCSI_INT,
+			.conn_only = 1,
+		}, {
+			.param = ISCSI_PARAM_TARGET_NAME,
+			.conn_only = 0,
+			.type = ISCSI_STRING,
+			.value = session->target_name,
+		}, {
+			.param = ISCSI_PARAM_TPGT,
+			.value = &session->portal_group_tag,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_PERSISTENT_ADDRESS,
+			.value = session->nrec.conn[conn->id].address,
+			.type = ISCSI_STRING,
+			.conn_only = 1,
+		}, {
+			.param = ISCSI_PARAM_PERSISTENT_PORT,
+			.value = &session->nrec.conn[conn->id].port,
+			.type = ISCSI_INT,
+			.conn_only = 1,
+		}, {
+			.param = ISCSI_PARAM_SESS_RECOVERY_TMO,
+			.value = &session->replacement_timeout,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_USERNAME,
+			.value = session->username,
+			.type = ISCSI_STRING,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_USERNAME_IN,
+			.value = session->username_in,
+			.type = ISCSI_STRING,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_PASSWORD,
+			.value = session->password,
+			.type = ISCSI_STRING,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_PASSWORD_IN,
+			.value = session->password_in,
+			.type = ISCSI_STRING,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_FAST_ABORT,
+			.value = &session->fast_abort,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_ABORT_TMO,
+			.value = &session->abort_timeout,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_LU_RESET_TMO,
+			.value = &session->lu_reset_timeout,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_TGT_RESET_TMO,
+			.value = &session->tgt_reset_timeout,
+			.type = ISCSI_INT,
+			.conn_only = 0,
+		}, {
+			.param = ISCSI_PARAM_PING_TMO,
+			.value = &conn->noop_out_timeout,
+			.type = ISCSI_INT,
+			.conn_only = 1,
+		}, {
+			.param = ISCSI_PARAM_RECV_TMO,
+			.value = &conn->noop_out_interval,
+			.type = ISCSI_INT,
+			.conn_only = 1,
+		}, {
+			.param = ISCSI_PARAM_IFACE_NAME,
+			.value = session->nrec.iface.name,
+			.type = ISCSI_STRING,
+		}, {
+			.param = ISCSI_PARAM_INITIATOR_NAME,
+			.value = session->initiator_name,
+			.type = ISCSI_STRING,
+		},
+	};
+
+	session->param_mask = ~0ULL;
+	if (!(t->caps & CAP_MULTI_R2T))
+		session->param_mask &= ~ISCSI_MAX_R2T;
+	if (!(t->caps & CAP_HDRDGST))
+		session->param_mask &= ~ISCSI_HDRDGST_EN;
+	if (!(t->caps & CAP_DATADGST))
+		session->param_mask &= ~ISCSI_DATADGST_EN;
+	if (!(t->caps & CAP_MARKERS)) {
+		session->param_mask &= ~ISCSI_IFMARKER_EN;
+		session->param_mask &= ~ISCSI_OFMARKER_EN;
+	}
+
+	/* some llds will send nops internally */
+	if (!iscsi_sysfs_session_supports_nop(session->id)) {
+		session->param_mask &= ~ISCSI_PING_TMO;
+		session->param_mask &= ~ISCSI_RECV_TMO;
+	}
+
+	/* Entered full-feature phase! */
+	for (i = 0; i < MAX_SESSION_PARAMS; i++) {
+		if (conn->id != 0 && !conntbl[i].conn_only)
+			continue;
+
+		if (!(session->param_mask & (1ULL << conntbl[i].param)))
+			continue;
+
+		rc = ipc->set_param(session->t->handle, session->id,
+				   conn->id, conntbl[i].param, conntbl[i].value,
+				   conntbl[i].type);
+		if (rc && rc != -ENOSYS) {
+			log_error("can't set operational parameter %d for "
+				  "connection %d:%d, retcode %d (%d)",
+				  conntbl[i].param, session->id, conn->id,
+				  rc, errno);
+			return EPERM;
+		}
+
+		if (rc == -ENOSYS) {
+			switch (conntbl[i].param) {
+			case ISCSI_PARAM_PING_TMO:
+				/*
+				 * older kernels may not support nops
+				 * in kernel
+				 */
+				conn->userspace_nop = 1;
+				break;
+#if 0
+TODO handle this
+			case ISCSI_PARAM_INITIATOR_NAME:
+				/* use host level one instead */
+				hosttbl[ISCSI_HOST_PARAM_INITIATOR_NAME].set = 1;
+				break;
+#endif
+			}
+		}
+
+		print_param_value(conntbl[i].param, conntbl[i].value,
+				  conntbl[i].type);
+	}
+
+	return 0;
+}
+
+int iscsi_host_set_net_params(struct iface_rec *iface,
+			      struct iscsi_session *session)
+{
+	struct iscsi_transport *t = session->t;
+	int rc = 0;
+
+	log_debug(3, "setting iface %s, dev %s, set ip %s, hw %s, "
+		  "transport %s.\n",
+		  iface->name, iface->netdev, iface->ipaddress,
+		  iface->hwaddress, iface->transport_name);
+
+	if (!t->template->set_host_ip)
+		return 0;
+
+	/* if we need to set the ip addr then set all the iface net settings */
+	if (!iface_is_bound_by_ipaddr(iface)) {
+		log_warning("Please set the iface.ipaddress for iface %s, "
+			    "then retry the login command.\n", iface->name);
+		return EINVAL;
+	}
+
+	rc = host_set_param(t, session->hostno,
+			    ISCSI_HOST_PARAM_IPADDRESS,
+			    iface->ipaddress, ISCSI_STRING);
+	if (rc)
+		return rc;
+
+	if (iface_is_bound_by_netdev(iface)) {
+		rc = host_set_param(t, session->hostno,
+				    ISCSI_HOST_PARAM_NETDEV_NAME,
+				    iface->netdev, ISCSI_STRING);
+		if (rc)
+			return rc;
+	}
+
+	if (iface_is_bound_by_hwaddr(iface)) {
+		rc = host_set_param(t, session->hostno,
+				    ISCSI_HOST_PARAM_HWADDRESS,
+				    iface->hwaddress, ISCSI_STRING);
+		if (rc)
+			return rc;
+	}
+	return 0;
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/initiator.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/initiator.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/initiator.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/initiator.h	2011-08-14 16:48:25.000000000 -0500
@@ -39,25 +39,18 @@
 #define INITIATOR_NAME_FILE	ISCSI_CONFIG_ROOT"initiatorname.iscsi"
 
 #define PID_FILE		"/var/run/iscsid.pid"
+#ifndef LOCK_DIR
 #define LOCK_DIR		"/var/lock/iscsi"
-#define LOCK_FILE		"/var/lock/iscsi/lock"
-#define LOCK_WRITE_FILE		"/var/lock/iscsi/lock.write"
-
-typedef enum iscsi_conn_state_e {
-	STATE_FREE,
-	STATE_XPT_WAIT,
-	STATE_IN_LOGIN,
-	STATE_LOGGED_IN,
-	STATE_IN_LOGOUT,
-	STATE_LOGOUT_REQUESTED,
-	STATE_CLEANUP_WAIT,
-} iscsi_conn_state_e;
+#endif
+#define LOCK_FILE		LOCK_DIR"/lock"
+#define LOCK_WRITE_FILE		LOCK_DIR"/lock.write"
 
 typedef enum iscsi_session_r_stage_e {
 	R_STAGE_NO_CHANGE,
 	R_STAGE_SESSION_CLEANUP,
 	R_STAGE_SESSION_REOPEN,
 	R_STAGE_SESSION_REDIRECT,
+	R_STAGE_SESSION_DESTOYED,
 } iscsi_session_r_stage_e;
 
 typedef enum conn_login_status_e {
@@ -67,6 +60,7 @@ typedef enum conn_login_status_e {
 	CONN_LOGIN_RETRY		= 3,
 	CONN_LOGIN_IMM_RETRY		= 4,
 	CONN_LOGIN_IMM_REDIRECT_RETRY	= 5,
+	CONN_LOGIN_AUTH_FAILED		= 6,
 } conn_login_status_e;
 
 enum iscsi_login_status {
@@ -88,6 +82,7 @@ typedef enum iscsi_event_e {
 	EV_CONN_ERROR,
 	EV_CONN_LOGOUT_TIMER,
 	EV_CONN_STOP,
+	EV_CONN_LOGIN,
 } iscsi_event_e;
 
 struct queue_task;
@@ -112,18 +107,18 @@ typedef struct iscsi_login_context {
 
 struct iscsi_session;
 struct iscsi_conn;
-struct iscsi_conn_context;
+struct iscsi_ev_context;
 
 /* daemon's connection structure */
 typedef struct iscsi_conn {
 	uint32_t id;
 	struct iscsi_session *session;
 	iscsi_login_context_t login_context;
-	struct iscsi_conn_context *recv_context;
+	struct iscsi_ev_context *recv_context;
 	struct queue_task *logout_qtask;
 	char data[ISCSI_DEF_MAX_RECV_SEG_LEN];
 	char host[NI_MAXHOST];	/* scratch */
-	iscsi_conn_state_e state;
+	enum iscsi_conn_state state;
 	int userspace_nop;
 
 	struct timeval initial_connect_time;
@@ -131,7 +126,7 @@ typedef struct iscsi_conn {
 	actor_t nop_out_timer;
 
 #define CONTEXT_POOL_MAX 32
-	struct iscsi_conn_context *context_pool[CONTEXT_POOL_MAX];
+	struct iscsi_ev_context *context_pool[CONTEXT_POOL_MAX];
 
 	/* login state machine */
 	int current_stage;
@@ -140,6 +135,11 @@ typedef struct iscsi_conn {
 	conn_login_status_e status;
 
 	/* tcp/socket settings */
+
+	/*
+	 * Either a tcp/ip or a netlink socket to do
+	 * IO through.
+	 */
 	int socket_fd;
 	/* address being used for normal session connection */
 	struct sockaddr_storage saddr;
@@ -173,7 +173,7 @@ typedef struct iscsi_conn {
 	uint32_t max_xmit_dlength;	/* the value declared by the target */
 } iscsi_conn_t;
 
-struct iscsi_conn_context {
+struct iscsi_ev_context {
 	struct actor actor;
 	struct iscsi_conn *conn;
 	int allocated;
@@ -201,6 +201,7 @@ typedef struct iscsi_session {
 	uint32_t hostno;
 	char netdev[IFNAMSIZ];
 	struct iscsi_transport *t;
+	uint8_t use_ipc;
 	node_rec_t nrec; /* copy of original Node record in database */
 	unsigned int irrelevant_keys_bitmap;
 	int send_async_text;
@@ -242,7 +243,6 @@ typedef struct iscsi_session {
 	uint8_t password_in[AUTH_STR_MAX_LEN];
 	int password_in_length;
 	iscsi_conn_t conn[ISCSI_CONN_MAX];
-	int ctrl_fd;
 	uint64_t param_mask;
 
 	/* connection reopens during recovery */
@@ -256,8 +256,11 @@ typedef struct iscsi_session {
 	int lu_reset_timeout;
 	int abort_timeout;
 
-	/* sync up fields */
-	queue_task_t *sync_qtask;
+	/*
+	 * used for hw and sync up to notify caller that the operation
+	 * is complete
+	 */
+	queue_task_t *notify_qtask;
 } iscsi_session_t;
 
 /* login.c */
@@ -330,20 +333,25 @@ extern int iscsi_io_recv_pdu(iscsi_conn_
 /* initiator.c */
 extern int session_login_task(node_rec_t *rec, queue_task_t *qtask);
 extern int session_logout_task(int sid, queue_task_t *qtask);
-extern iscsi_session_t *session_find_by_sid(int sid);
-extern struct iscsi_conn_context *iscsi_conn_context_get(iscsi_conn_t *conn,
-						   int ev_size);
-extern void iscsi_conn_context_put(struct iscsi_conn_context *conn_context);
-extern void iscsi_sched_conn_context(struct iscsi_conn_context *context,
-				     struct iscsi_conn *conn, unsigned long tmo,
-				     int event);
-extern mgmt_ipc_err_e iscsi_sync_session(node_rec_t *rec, queue_task_t
+extern iscsi_session_t *session_find_by_sid(uint32_t sid);
+extern int iscsi_sync_session(node_rec_t *rec, queue_task_t
 					 *tsk, uint32_t sid);
-extern mgmt_ipc_err_e iscsi_host_send_targets(queue_task_t *qtask,
+extern int iscsi_host_send_targets(queue_task_t *qtask,
 			int host_no, int do_login, struct sockaddr_storage *ss);
-extern mgmt_ipc_err_e iscsi_host_set_param(int host_no, int param, char *value);
-extern void iscsi_async_session_creation(uint32_t host_no, uint32_t sid);
-extern void iscsi_async_session_destruction(uint32_t host_no, uint32_t sid);
+
 extern void free_initiator(void);
+extern void iscsi_initiator_init(void);
+
+/* initiator code common to discovery and normal sessions */
+extern int iscsi_session_set_params(struct iscsi_conn *conn);
+extern int iscsi_host_set_params(struct iscsi_session *session);
+extern int iscsi_host_set_net_params(struct iface_rec *iface,
+				     struct iscsi_session *session);
+extern void iscsi_copy_operational_params(struct iscsi_conn *conn,
+			struct iscsi_session_operational_config *session_conf,
+			struct iscsi_conn_operational_config *conn_conf);
+extern int iscsi_setup_authentication(struct iscsi_session *session,
+				      struct iscsi_auth_config *auth_cfg);
+extern int iscsi_setup_portal(struct iscsi_conn *conn, char *address, int port);
 
 #endif /* INITIATOR_H */
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/io.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/io.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/io.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/io.c	2011-08-14 16:48:25.000000000 -0500
@@ -26,11 +26,14 @@
 #include <fcntl.h>
 #include <sys/poll.h>
 #include <sys/ioctl.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 
 #include "types.h"
 #include "iscsi_proto.h"
+#include "iscsi_settings.h"
 #include "initiator.h"
 #include "iscsi_ipc.h"
 #include "log.h"
@@ -38,6 +41,7 @@
 #include "idbm.h"
 #include "iface.h"
 #include "sysdeps.h"
+#include "dcb_app.h"
 
 #define LOG_CONN_CLOSED(conn) \
 do { \
@@ -53,6 +57,13 @@ do { \
 	log_error("Connection to Discovery Address %s failed", conn->host); \
 } while (0)
 
+union sockaddr_u {
+	struct sockaddr_storage	ss;
+	struct sockaddr sa;
+	struct sockaddr_in si;
+	struct sockaddr_in6 si6;
+};
+
 static int timedout;
 
 static void
@@ -76,6 +87,93 @@ set_non_blocking(int fd)
 
 }
 
+static int select_priority(struct iscsi_conn *conn, int pri_mask)
+{
+	int msk;
+
+	if (!pri_mask)
+		return 0;
+
+	/*
+	 * TODO: Configure priority selection from the mask
+	 * For now, just always take the highest
+	 */
+
+	/* Find highest bit set */
+	while ((msk = pri_mask & (pri_mask - 1)))
+		pri_mask = msk;
+
+	return ffs(pri_mask) - 1;
+}
+
+static int
+inet_cmp_addr(const union sockaddr_u *s1, const union sockaddr_u *s2)
+{
+	const struct sockaddr_in *si1 = &s1->si;
+	const struct sockaddr_in *si2 = &s2->si;
+
+	return si1->sin_addr.s_addr != si2->sin_addr.s_addr;
+}
+
+static int
+inet6_cmp_addr(const union sockaddr_u *s1, const union sockaddr_u *s2)
+{
+	const struct sockaddr_in6 *si1 = &s1->si6;
+	const struct sockaddr_in6 *si2 = &s2->si6;
+
+	return memcmp(&si1->sin6_addr, &si2->sin6_addr, sizeof(si1->sin6_addr));
+}
+
+static char *
+find_ifname(const struct ifaddrs *ifa, const union sockaddr_u *ss)
+{
+	for (; ifa; ifa = ifa->ifa_next) {
+		if (!ifa->ifa_addr)
+			continue;
+
+		if (ss->ss.ss_family != ifa->ifa_addr->sa_family)
+			continue;
+		switch (ss->ss.ss_family) {
+		case AF_INET:
+			if (inet_cmp_addr(ss, (union sockaddr_u *)ifa->ifa_addr) == 0)
+				return ifa->ifa_name;
+			break;
+		case AF_INET6:
+			if (inet6_cmp_addr(ss, (union sockaddr_u *)ifa->ifa_addr) == 0)
+				return ifa->ifa_name;
+			break;
+		}
+	}
+
+	return NULL;
+}
+
+static void set_dcb_priority(struct iscsi_conn *conn, const char *devname)
+{
+	int pri_mask = 0;
+
+	pri_mask = get_dcb_app_pri_by_stream_port(devname, ISCSI_DEFAULT_PORT);
+	if (pri_mask < 0)
+		log_debug(2, "Getting priority for %s returned %d",
+				devname, pri_mask);
+	else if (pri_mask == 0)
+		log_debug(2, "No priority for %s", devname);
+	else {
+		int pri = select_priority(conn, pri_mask);
+		int rc;
+
+		log_debug(1, "Setting socket %d priority to %d",
+				conn->socket_fd, pri);
+		rc = setsockopt(conn->socket_fd, SOL_SOCKET,
+				SO_PRIORITY, &pri, sizeof(pri));
+		if (rc < 0) {
+			log_warning("Setting socket %d priority to %d failed "
+					"with errno %d", conn->socket_fd,
+					pri, errno);
+		}
+	}
+}
+
 #if 0
 /* not used by anyone */
 static int get_hwaddress_from_netdev(char *netdev, char *hwaddress)
@@ -201,15 +299,20 @@ static int bind_conn_to_iface(iscsi_conn
 {
 	struct iscsi_session *session = conn->session;
 
+	if (strcmp(iface->transport_name, DEFAULT_TRANSPORT))
+		return 0;
+
 	memset(session->netdev, 0, IFNAMSIZ);
-	if (iface_is_bound_by_hwaddr(iface) &&
-	    net_get_netdev_from_hwaddress(iface->hwaddress, session->netdev)) {
-		log_error("Cannot match %s to net/scsi interface.",
-			  iface->hwaddress);
-                return -1;
-	} else if (iface_is_bound_by_netdev(iface))
+	if (iface_is_bound_by_hwaddr(iface)) {
+		if (net_get_netdev_from_hwaddress(iface->hwaddress,
+						  session->netdev)) {
+			log_error("Cannot match %s to net/scsi interface.",
+				  iface->hwaddress);
+			return -1;
+		}
+	} else if (iface_is_bound_by_netdev(iface)) {
 		strcpy(session->netdev, iface->netdev);
-	else if (iface_is_bound_by_ipaddr(iface)) {
+	} else if (iface_is_bound_by_ipaddr(iface)) {
 		/*
 		 * we never supported this but now with offload having to
 		 * set the ip address in the iface, useris may forget to
@@ -260,10 +363,8 @@ iscsi_io_tcp_connect(iscsi_conn_t *conn,
 		return -1;
 	}
 
-	if (conn->session) {
-		if (bind_conn_to_iface(conn, &conn->session->nrec.iface))
-			return -1;
-	}
+	if (bind_conn_to_iface(conn, &conn->session->nrec.iface))
+		return -1;
 
 	onearg = 1;
 	rc = setsockopt(conn->socket_fd, IPPROTO_TCP, TCP_NODELAY, &onearg,
@@ -320,6 +421,10 @@ iscsi_io_tcp_connect(iscsi_conn_t *conn,
 	log_debug(1, "connecting to %s:%s", conn->host, serv);
 	if (non_blocking)
 		set_non_blocking(conn->socket_fd);
+
+	if (conn->session->netdev[0])
+		set_dcb_priority(conn, conn->session->netdev);
+
 	rc = connect(conn->socket_fd, (struct sockaddr *) ss, sizeof (*ss));
 	return rc;
 }
@@ -331,7 +436,7 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, in
 	struct pollfd pdesc;
 	char serv[NI_MAXSERV], lserv[NI_MAXSERV];
 	struct sockaddr_storage ss;
-	socklen_t len = sizeof(ss);
+	socklen_t len;
 
 	pdesc.fd = conn->socket_fd;
 	pdesc.events = POLLOUT;
@@ -368,8 +473,9 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, in
 	}
 
 	len = sizeof(ss);
-	if (log_level > 0 &&
-	    getsockname(conn->socket_fd, (struct sockaddr *) &ss, &len) >= 0) {
+	if (log_level > 0 || !conn->session->netdev[0])
+		rc = getsockname(conn->socket_fd, (struct sockaddr *)&ss, &len);
+	if (log_level > 0 && rc >= 0) {
 		getnameinfo((struct sockaddr *) &conn->saddr,
 			    sizeof(conn->saddr), conn->host,
 			    sizeof(conn->host), serv, sizeof(serv),
@@ -381,6 +487,22 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, in
 		log_debug(1, "connected local port %s to %s:%s",
 			  lserv, conn->host, serv);
 	}
+
+	if (!conn->session->netdev[0] && rc >= 0) {
+		struct ifaddrs *ifa;
+		char *ifname;
+
+		rc = getifaddrs(&ifa);
+		if (rc < 0)
+			log_error("getifaddrs failed with %d\n", errno);
+		else {
+			ifname = find_ifname(ifa, (union sockaddr_u *)&ss);
+			if (ifname)
+				set_dcb_priority(conn, ifname);
+			freeifaddrs(ifa);
+		}
+	}
+
 	return 1;
 }
 
@@ -401,7 +523,6 @@ iscsi_io_connect(iscsi_conn_t *conn)
 	int rc, ret;
 	struct sigaction action;
 	struct sigaction old;
-	char serv[NI_MAXSERV];
 
 	/* set a timeout, since the socket calls may take a long time to
 	 * timeout on their own
@@ -420,22 +541,21 @@ iscsi_io_connect(iscsi_conn_t *conn)
 	 */
 	rc = iscsi_io_tcp_connect(conn, 0);
 	if (timedout) {
+		log_error("connect to %s timed out", conn->host);
+			  
 		log_debug(1, "socket %d connect timed out", conn->socket_fd);
 		ret = 0;
 		goto done;
 	} else if (rc < 0) {
-		getnameinfo((struct sockaddr *) &conn->saddr,
-			    sizeof(conn->saddr),
-			    conn->host, sizeof(conn->host), serv, sizeof(serv),
-			    NI_NUMERICHOST|NI_NUMERICSERV);
-		log_error("cannot make connection to %s:%s (%d)",
-			  conn->host, serv, errno);
+		log_error("cannot make connection to %s: %s",
+			  conn->host, strerror(errno));
 		close(conn->socket_fd);
 		ret = 0;
 		goto done;
 	} else if (log_level > 0) {
 		struct sockaddr_storage ss;
 		char lserv[NI_MAXSERV];
+		char serv[NI_MAXSERV];
 		socklen_t salen = sizeof(ss);
 
 		if (getsockname(conn->socket_fd, (struct sockaddr *) &ss,
@@ -503,7 +623,7 @@ iscsi_io_send_pdu(iscsi_conn_t *conn, st
 	/* set a timeout, since the socket calls may take a long time
 	 * to timeout on their own
 	 */
-	if (!ipc) {
+	if (!session->use_ipc) {
 		memset(&action, 0, sizeof (struct sigaction));
 		memset(&old, 0, sizeof (struct sigaction));
 		action.sa_sigaction = NULL;
@@ -566,7 +686,7 @@ iscsi_io_send_pdu(iscsi_conn_t *conn, st
 	else
 		pad_bytes = 0;
 
-	if (ipc)
+	if (session->use_ipc)
 		ipc->send_pdu_begin(session->t->handle, session->id,
 				    conn->id, end - header,
 				    ntoh24(hdr->dlength) + pad_bytes);
@@ -575,8 +695,8 @@ iscsi_io_send_pdu(iscsi_conn_t *conn, st
 		vec[0].iov_base = header;
 		vec[0].iov_len = end - header;
 
-		if (!ipc)
-			rc = writev(session->ctrl_fd, vec, 1);
+		if (!session->use_ipc)
+			rc = writev(conn->socket_fd, vec, 1);
 		else
 			rc = ipc->writev(0, vec, 1);
 		if (timedout) {
@@ -603,13 +723,13 @@ iscsi_io_send_pdu(iscsi_conn_t *conn, st
 		vec[1].iov_base = (void *) &pad;
 		vec[1].iov_len = pad_bytes;
 
-		if (!ipc)
-			rc = writev(session->ctrl_fd, vec, 2);
+		if (!session->use_ipc)
+			rc = writev(conn->socket_fd, vec, 2);
 		else
 			rc = ipc->writev(0, vec, 2);
 		if (timedout) {
 			log_error("socket %d write timed out",
-			       conn->socket_fd);
+				  conn->socket_fd);
 			ret = 0;
 			goto done;
 		} else if ((rc <= 0) && (errno != EAGAIN)) {
@@ -627,7 +747,7 @@ iscsi_io_send_pdu(iscsi_conn_t *conn, st
 		}
 	}
 
-	if (ipc) {
+	if (session->use_ipc) {
 		if (ipc->send_pdu_end(session->t->handle, session->id,
 				      conn->id, &rc)) {
 			ret = 0;
@@ -638,7 +758,7 @@ iscsi_io_send_pdu(iscsi_conn_t *conn, st
 	ret = 1;
 
       done:
-	if (!ipc) {
+	if (!session->use_ipc) {
 		alarm(0);
 		sigaction(SIGALRM, &old, NULL);
 		timedout = 0;
@@ -670,7 +790,7 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 	/* set a timeout, since the socket calls may take a long
 	 * time to timeout on their own
 	 */
-	if (!ipc) {
+	if (!session->use_ipc) {
 		memset(&action, 0, sizeof (struct sigaction));
 		memset(&old, 0, sizeof (struct sigaction));
 		action.sa_sigaction = NULL;
@@ -680,7 +800,10 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 		timedout = 0;
 		alarm(timeout);
 	} else {
-		if (ipc->recv_pdu_begin(conn)) {
+		failed = ipc->recv_pdu_begin(conn);
+		if (failed == -EAGAIN)
+			return -EAGAIN;
+		else if (failed < 0) {
 			failed = 1;
 			goto done;
 		}
@@ -688,14 +811,14 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 
 	/* read a response header */
 	do {
-		if (!ipc)
-			rlen = read(session->ctrl_fd, header,
+		if (!session->use_ipc)
+			rlen = read(conn->socket_fd, header,
 					sizeof (*hdr) - h_bytes);
 		else
 			rlen = ipc->read(header, sizeof (*hdr) - h_bytes);
 		if (timedout) {
 			log_error("socket %d header read timed out",
-			       conn->socket_fd);
+				  conn->socket_fd);
 			failed = 1;
 			goto done;
 		} else if (rlen == 0) {
@@ -714,7 +837,7 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 	} while (h_bytes < sizeof (*hdr));
 
 	log_debug(4, "read %d PDU header bytes, opcode 0x%x, dlength %u, "
-		 "data %p, max %u", h_bytes, hdr->opcode,
+		 "data %p, max %u", h_bytes, hdr->opcode & ISCSI_OPCODE_MASK,
 		 ntoh24(hdr->dlength), data, max_data_length);
 
 	/* check for additional headers */
@@ -745,14 +868,14 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 	/* read the rest into our buffer */
 	d_bytes = 0;
 	while (d_bytes < dlength) {
-		if (!ipc)
-			rlen = read(session->ctrl_fd, data + d_bytes,
+		if (!session->use_ipc)
+			rlen = read(conn->socket_fd, data + d_bytes,
 					dlength - d_bytes);
 		else
 			rlen = ipc->read(data + d_bytes, dlength - d_bytes);
 		if (timedout) {
 			log_error("socket %d data read timed out",
-			       conn->socket_fd);
+				  conn->socket_fd);
 			failed = 1;
 			goto done;
 		} else if (rlen == 0) {
@@ -772,7 +895,7 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 	/* handle PDU data padding.
 	 * data is padded in case of kernel_io */
 	pad = dlength % ISCSI_PAD_LEN;
-	if (pad && !ipc) {
+	if (pad && !session->use_ipc) {
 		int pad_bytes = pad = ISCSI_PAD_LEN - pad;
 		char bytes[ISCSI_PAD_LEN];
 
@@ -780,7 +903,7 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 			rlen = read(conn->socket_fd, &bytes, pad_bytes);
 			if (timedout) {
 				log_error("socket %d pad read timed out",
-				       conn->socket_fd);
+					  conn->socket_fd);
 				failed = 1;
 				goto done;
 			} else if (rlen == 0) {
@@ -828,7 +951,7 @@ iscsi_io_recv_pdu(iscsi_conn_t *conn, st
 	}
 
 done:
-	if (!ipc) {
+	if (!session->use_ipc) {
 		alarm(0);
 		sigaction(SIGALRM, &old, NULL);
 	} else {
@@ -840,7 +963,7 @@ done:
 
 	if (timedout || failed) {
 		timedout = 0;
-		return 0;
+		return -EIO;
 	}
 
 	return h_bytes + ahs_bytes + d_bytes;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsiadm.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsiadm.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsiadm.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsiadm.c	2011-08-14 16:48:25.000000000 -0500
@@ -4,6 +4,7 @@
  * Copyright (C) 2004 Dmitry Yusupov, Alex Aizman
  * Copyright (C) 2006 Mike Christie
  * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011 Dell Inc.
  * maintained by open-iscsi@googlegroups.com
  *
  * This program is free software; you can redistribute it and/or modify
@@ -48,10 +49,12 @@
 #include "session_mgmt.h"
 #include "iscsid_req.h"
 #include "isns-proto.h"
+#include "iscsi_err.h"
+#include "iscsi_ipc.h"
 
-struct iscsi_ipc *ipc = NULL; /* dummy */
 static char program_name[] = "iscsiadm";
 static char config_file[TARGET_NAME_MAXLEN];
+extern struct iscsi_ipc *ipc;
 
 enum iscsiadm_mode {
 	MODE_DISCOVERY,
@@ -69,7 +72,9 @@ enum iscsiadm_op {
 	OP_DELETE		= 0x2,
 	OP_UPDATE		= 0x4,
 	OP_SHOW			= 0x8,
-	OP_NONPERSISTENT	= 0x10
+	OP_NONPERSISTENT	= 0x10,
+	OP_APPLY		= 0x20,
+	OP_APPLY_ALL		= 0x40
 };
 
 static struct option const long_options[] =
@@ -108,18 +113,18 @@ static void usage(int status)
 			program_name);
 	else {
 		printf("\
-iscsiadm -m discovery2 [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -Dl ] ] | [ [ -p ip:port -t type] \
+iscsiadm -m discoverydb [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -Dl ] ] | [ [ -p ip:port -t type] \
 [ -o operation ] [ -n name ] [ -v value ] [ -lD ] ] \n\
 iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] [ -l | -D ] ] \n\
 iiscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] \
 [ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
 iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]\n\
-iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
+iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
 iscsiadm -m fw [ -l ]\n\
-iscsiadm -m host [ -P printlevel ] [ -H hostno ]\n\
+iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ]\n\
 iscsiadm -k priority\n");
 	}
-	exit(status == 0 ? 0 : -1);
+	exit(status);
 }
 
 static int
@@ -137,6 +142,10 @@ str_to_op(char *str)
 		op = OP_SHOW;
 	else if (!strcmp("nonpersistent", str))
 		op = OP_NONPERSISTENT;
+	else if (!strcmp("apply", str))
+		op = OP_APPLY;
+	else if (!strcmp("applyall", str))
+		op = OP_APPLY_ALL;
 	else
 		op = OP_NOOP;
 
@@ -212,7 +221,7 @@ static void kill_iscsid(int priority)
 	req.command = MGMT_IPC_IMMEDIATE_STOP;
 	rc = iscsid_exec_req(&req, &rsp, 0);
 	if (rc) {
-		iscsid_handle_error(rc);
+		iscsi_err_print_msg(rc);
 		log_error("Could not stop iscsid. Trying sending iscsid "
 			  "SIGTERM or SIGKILL signals manually\n");
 	}
@@ -251,12 +260,12 @@ static int print_ifaces(struct iface_rec
 		break;
 	default:
 		log_error("Invalid info level %d. Try 0 - 1.", info_level);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	if (!num_found) {
 		log_error("No interfaces found.");
-		err = ENODEV;
+		err = ISCSI_ERR_NO_OBJS_FOUND;
 	}
 	return err;
 }
@@ -264,15 +273,10 @@ static int print_ifaces(struct iface_rec
 static int
 match_startup_mode(node_rec_t *rec, char *mode)
 {
-	/*
-	 * we always skip onboot because this should be handled by
-	 * something else
-	 */
-	if (rec->startup == ISCSI_STARTUP_ONBOOT)
-		return -1;
-
 	if ((!strcmp(mode, "automatic") &&
 	    rec->startup == ISCSI_STARTUP_AUTOMATIC) ||
+	    (!strcmp(mode, "onboot") &&
+	    rec->startup == ISCSI_STARTUP_ONBOOT) ||
 	    (!strcmp(mode, "manual") &&
 	    rec->startup == ISCSI_STARTUP_MANUAL) ||
 	    !strcmp(mode, "all"))
@@ -281,6 +285,8 @@ match_startup_mode(node_rec_t *rec, char
 	/* support conn or session startup params */
 	if ((!strcmp(mode, "automatic") &&
 	    rec->conn[0].startup == ISCSI_STARTUP_AUTOMATIC) ||
+	    (!strcmp(mode, "onboot") &&
+	    rec->conn[0].startup == ISCSI_STARTUP_ONBOOT) ||
 	    (!strcmp(mode, "manual") &&
 	    rec->conn[0].startup == ISCSI_STARTUP_MANUAL) ||
 	    !strcmp(mode, "all"))
@@ -294,13 +300,18 @@ for_each_session(struct node_rec *rec, i
 {
 	int err, num_found = 0;
 
-	err = iscsi_sysfs_for_each_session(rec, &num_found, fn);
+	if (rec && rec->session.info) {
+		num_found = 1;
+		err = fn(rec, rec->session.info);
+	} else {
+		err = iscsi_sysfs_for_each_session(rec, &num_found, fn);
+	}
 	if (err)
-		log_error("Could not execute operation on all sessions. Err "
-			  "%d.", err);
+		log_error("Could not execute operation on all sessions: %s",
+			  iscsi_err_to_str(err));
 	else if (!num_found) {
-		log_error("No portal found.");
-		err = ENODEV;
+		log_error("No session found.");
+		err = ISCSI_ERR_NO_OBJS_FOUND;
 	}
 
 	return err;
@@ -313,7 +324,7 @@ static int link_recs(void *data, struct 
 
 	rec_copy = calloc(1, sizeof(*rec_copy));
 	if (!rec_copy)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	memcpy(rec_copy, rec, sizeof(*rec_copy));
 	INIT_LIST_HEAD(&rec_copy->list);
 	list_add_tail(&rec_copy->list, list);
@@ -326,7 +337,6 @@ __logout_by_startup(void *data, struct l
 {
 	char *mode = data;
 	node_rec_t rec;
-	int rc = 0;
 
 	memset(&rec, 0, sizeof(node_rec_t));
 	if (idbm_rec_read(&rec, info->targetname, info->tpgt,
@@ -352,74 +362,188 @@ __logout_by_startup(void *data, struct l
 	if (rec.startup == ISCSI_STARTUP_ONBOOT)
 		return -1;
 
-	if (!match_startup_mode(&rec, mode))
-		rc = iscsi_logout_portal(info, list);
-	return rc;
+	if (match_startup_mode(&rec, mode))
+		return -1;
+
+	return iscsi_logout_portal(info, list);
 }
 
 static int
 logout_by_startup(char *mode)
 {
 	int nr_found;
+	int rc;
 
 	if (!mode || !(!strcmp(mode, "automatic") || !strcmp(mode, "all") ||
 	    !strcmp(mode,"manual"))) {
 		log_error("Invalid logoutall option %s.", mode);
-		usage(0);
-		return EINVAL;
+		usage(ISCSI_ERR_INVAL);
+		return ISCSI_ERR_INVAL;
 	}
 
-	return iscsi_logout_portals(mode, &nr_found, 1, __logout_by_startup);
+	rc = iscsi_logout_portals(mode, &nr_found, 1, __logout_by_startup);
+	if (rc == ISCSI_ERR_NO_OBJS_FOUND)
+		log_error("No matching sessions found");
+	return rc; 
+}
+
+struct startup_data {
+	char *mode;
+	struct list_head all_logins;
+	struct list_head leading_logins;
+};
+
+static int link_startup_recs(void *data, struct node_rec *rec)
+{
+	struct startup_data *startup = data;
+	struct node_rec *rec_copy;
+
+	if (match_startup_mode(rec, startup->mode))
+		return -1;
+
+	rec_copy = calloc(1, sizeof(*rec_copy));
+	if (!rec_copy)
+		return ISCSI_ERR_NOMEM;
+	memcpy(rec_copy, rec, sizeof(*rec_copy));
+	INIT_LIST_HEAD(&rec_copy->list);
+
+	if (rec_copy->leading_login)
+		list_add_tail(&rec_copy->list, &startup->leading_logins);
+	else
+		list_add_tail(&rec_copy->list, &startup->all_logins);
+	return 0;
 }
 
-/*
- * TODO: merged this and logout into the common for_each_rec by making
- * the matching more generic
- */
 static int
-__login_by_startup(void *data, struct list_head *list, struct node_rec *rec)
+__do_leading_login(void *data, struct list_head *list, struct node_rec *rec)
 {
-	char *mode = data;
-	/*
-	 * we always skip onboot because this should be handled by
-	 * something else
-	 */
-	if (rec->startup == ISCSI_STARTUP_ONBOOT)
+	struct iface_rec *pattern_iface = data;
+	int nr_found;
+
+	/* Skip any records that do not match the pattern iface */
+	if (!iface_match(pattern_iface, &rec->iface))
 		return -1;
 
-	if (match_startup_mode(rec, mode))
+	/*
+	 * If there is an existing session that matcthes the target,
+	 * the leading login is complete.
+	 */
+	if (iscsi_sysfs_for_each_session(rec, &nr_found, iscsi_match_target)) {
+		log_debug(1, "Skipping %s: Already a session for that target",
+			  rec->name);
 		return -1;
+	}
 
-	iscsi_login_portal(NULL, list, rec);
-	return 0;
+	/* No existing session: Attempt a login. */
+	return iscsi_login_portal(NULL, list, rec);
 }
 
 static int
 login_by_startup(char *mode)
 {
-	int nr_found = 0, rc, err;
-	struct list_head rec_list;
+	int nr_found = 0, err, rc;
+	struct startup_data startup;
 
 	if (!mode || !(!strcmp(mode, "automatic") || !strcmp(mode, "all") ||
-	    !strcmp(mode,"manual"))) {
+		       !strcmp(mode,"manual") || !strcmp(mode, "onboot"))) {
 		log_error("Invalid loginall option %s.", mode);
-		usage(0);
-		return EINVAL;
+		usage(ISCSI_ERR_INVAL);
+		return ISCSI_ERR_INVAL;
 	}
 
-	INIT_LIST_HEAD(&rec_list);
-	rc = idbm_for_each_rec(&nr_found, &rec_list, link_recs);
-	err = iscsi_login_portals(mode, &nr_found, 1, &rec_list,
-				  __login_by_startup);
-	if (err && !rc)
-		rc = err;
+	/*
+	 * Filter all node records that match the given 'mode' into 2 lists:
+	 * Those with leading_login enabled, and those without.
+	 */
+	startup.mode = mode;
+	INIT_LIST_HEAD(&startup.all_logins);
+	INIT_LIST_HEAD(&startup.leading_logins);
+	err = idbm_for_each_rec(&nr_found, &startup, link_startup_recs);
+	if (err && (!list_empty(&startup.all_logins) ||
+		    !list_empty(&startup.leading_logins)))
+		/* log msg and try to log into what we found */
+		log_error("Could not read all records: %s",
+			  iscsi_err_to_str(err));
+	else if (list_empty(&startup.all_logins) &&
+		 list_empty(&startup.leading_logins)) {
+		if (err) {
+			log_error("Could not read node DB: %s.",
+				  iscsi_err_to_str(err));
+		} else {
+			log_error("No records found");
+			err = ISCSI_ERR_NO_OBJS_FOUND;
+		}
+		return err;
+	}
+	rc = err;
 
-	if (rc)
-		log_error("Could not log into all portals. Err %d.", rc);
-	else if (!nr_found) {
-		log_error("No records found!");
-		rc = ENODEV;
+	if (!list_empty(&startup.all_logins)) {
+		log_debug(1, "Logging into normal (non-leading-login) portals");
+		/* Login all regular (non-leading-login) portals first */
+		err = iscsi_login_portals(NULL, &nr_found, 1,
+				&startup.all_logins, iscsi_login_portal);
+		if (err)
+			log_error("Could not log into all portals");
+		if (err && !rc)
+			rc = err;
 	}
+
+	if (!list_empty(&startup.leading_logins)) {
+		/*
+		 * For each iface in turn, try to login all portals on that
+		 * iface that do not already have a session present.
+		 */
+		struct iface_rec *pattern_iface, *tmp_iface;
+		struct node_rec *rec, *tmp_rec;
+		struct list_head iface_list;
+		int missed_leading_login = 0;
+		log_debug(1, "Logging into leading-login portals");
+		INIT_LIST_HEAD(&iface_list);
+		iface_link_ifaces(&iface_list);
+		list_for_each_entry_safe(pattern_iface, tmp_iface, &iface_list,
+					 list) {
+			log_debug(1, "Establishing leading-logins via iface %s",
+				  pattern_iface->name);
+			err = iscsi_login_portals_safe(pattern_iface, &nr_found,
+						       1,
+						       &startup.leading_logins,
+						       __do_leading_login);
+			if (err)
+				log_error("Could not log into all portals on "
+					  "%s, trying next interface",
+					  pattern_iface->name);
+
+			/*
+			 * Note: We always try all iface records in case there
+			 * are targets that are associated with only a subset
+			 * of iface records.  __do_leading_login already
+			 * prevents duplicate sessions if an iface has succeded
+			 * for a particular target.
+			 */
+		}
+		/*
+		 * Double-check that all leading-login portals have at least
+		 * one session
+		 */
+		list_for_each_entry_safe(rec, tmp_rec, &startup.leading_logins,
+					 list) {
+			if (!iscsi_sysfs_for_each_session(rec, &nr_found,
+							  iscsi_match_target))
+				missed_leading_login++;
+			/*
+			 * Cleanup the list, since 'iscsi_login_portals_safe'
+			 * does not
+			 */
+			list_del(&rec->list);
+			free(rec);
+		}
+		if (missed_leading_login) {
+			log_error("Could not login all leading-login portals");
+			if (!rc)
+				rc = ISCSI_ERR_FATAL_LOGIN;
+		}
+	}
+
 	return rc;
 }
 
@@ -442,30 +566,22 @@ static int iscsi_logout_matched_portal(v
 	if (!iscsi_match_session(pattern_rec, info))
 		return -1;
 
-	/* we do not support this yet */
-	if (t->caps & CAP_FW_DB) {
-		log_error("Could not logout session of [sid: %d, "
-			  "target: %s, portal: %s,%d].", info->sid,
-			  info->targetname, info->persistent_address,
-			  info->port);
-		log_error("Logout not supported for driver: %s.", t->name);
-		return -1;
-	}
 	return iscsi_logout_portal(info, list);
 }
 
-static int iface_fn(void *data, node_rec_t *rec)
+static int rec_match_fn(void *data, node_rec_t *rec)
 {
 	struct rec_op_data *op_data = data;
 
 	if (!__iscsi_match_session(op_data->match_rec, rec->name,
 				   rec->conn[0].address, rec->conn[0].port,
-				   &rec->iface))
+				   &rec->iface, rec->session.sid))
 		return -1;
 	return op_data->fn(op_data->data, rec);
 }
 
-static int for_each_rec(struct node_rec *rec, void *data, idbm_iface_op_fn *fn)
+static int __for_each_matched_rec(int verbose, struct node_rec *rec,
+				  void *data, idbm_iface_op_fn *fn)
 {
 	struct rec_op_data op_data;
 	int nr_found = 0, rc;
@@ -475,30 +591,51 @@ static int for_each_rec(struct node_rec 
 	op_data.match_rec = rec;
 	op_data.fn = fn;
 
-	rc = idbm_for_each_rec(&nr_found, &op_data, iface_fn);
+	rc = idbm_for_each_rec(&nr_found, &op_data, rec_match_fn);
 	if (rc) {
-		log_error("Could not execute operation on all "
-			  "records. Err %d.", rc);
+		if (verbose)
+			log_error("Could not execute operation on all "
+				  "records: %s", iscsi_err_to_str(rc));
 	} else if (!nr_found) {
-		log_error("no records found!");
-		rc = ENODEV;
+		if (verbose)
+			log_error("No records found");
+		rc = ISCSI_ERR_NO_OBJS_FOUND;
 	}
 
 	return rc;
 }
 
+static int for_each_matched_rec(struct node_rec *rec, void *data,
+			        idbm_iface_op_fn *fn)
+{
+	return __for_each_matched_rec(1, rec, data, fn);
+}
+
+
 static int login_portals(struct node_rec *pattern_rec)
 {
 	struct list_head rec_list;
-	int err, ret, nr_found;
+	int nr_found, rc, err;
 
 	INIT_LIST_HEAD(&rec_list);
-	ret = for_each_rec(pattern_rec, &rec_list, link_recs);
-	err = iscsi_login_portals(NULL, &nr_found, 1, &rec_list,
+	err = for_each_matched_rec(pattern_rec, &rec_list, link_recs);
+	if (err == ISCSI_ERR_NO_OBJS_FOUND)
+		return err;
+	else if (err && list_empty(&rec_list))
+		return err;
+
+	rc = err;
+	/* if there is an err but some recs then try to login to what we have */
+
+	err = iscsi_login_portals(pattern_rec, &nr_found, 1, &rec_list,
 				  iscsi_login_portal);
-	if (err && !ret)
-		ret = err;
-	return ret;
+	if (err)
+		log_error("Could not log into all portals");
+
+	if (err && !rc)
+		rc = err;
+
+	return rc;
 }
 
 static int print_nodes(int info_level, struct node_rec *rec)
@@ -509,17 +646,16 @@ static int print_nodes(int info_level, s
 	switch (info_level) {
 	case 0:
 	case -1:
-		if (for_each_rec(rec, NULL, idbm_print_node_flat))
-			rc = -1;
+		rc = for_each_matched_rec(rec, NULL, idbm_print_node_flat);
 		break;
 	case 1:
 		memset(&tmp_rec, 0, sizeof(node_rec_t));
-		if (for_each_rec(rec, &tmp_rec, idbm_print_node_and_iface_tree))
-			rc = -1;
+		rc = for_each_matched_rec(rec, &tmp_rec,
+					  idbm_print_node_and_iface_tree);
 		break;
 	default:
 		log_error("Invalid info level %d. Try 0 or 1.", info_level);
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 	}
 
 	return rc;
@@ -586,7 +722,7 @@ session_stats(void *data, struct session
 
 	rc = iscsid_exec_req(&req, &rsp, 1);
 	if (rc)
-		return EIO;
+		return rc;
 
 	printf("Stats for session [sid: %d, target: %s, portal: "
 		"%s,%d]\n",
@@ -665,14 +801,14 @@ static int add_static_rec(int *found, ch
 	rec = calloc(1, sizeof(*rec));
 	if (!rec) {
 		log_error("Could not allocate memory for node addition");
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto done;
 	}
 
 	drec = calloc(1, sizeof(*drec));
 	if (!drec) {
 		log_error("Could not allocate memory for node addition");
-		rc = ENOMEM;
+		rc = ISCSI_ERR_NOMEM;
 		goto free_rec;
 	}
 	drec->type = DISCOVERY_TYPE_STATIC;
@@ -715,10 +851,10 @@ static int add_static_portal(int *found,
 
 	if (strlen(rec->conn[0].address) &&
 	    strcmp(rec->conn[0].address, ip))
-		return 0;
+		return -1;
 
 	if (rec->conn[0].port != -1 && rec->conn[0].port != port)
-		return 0;
+		return -1;
 
 	return add_static_rec(found, targetname, tpgt, ip, port,
 			      &rec->iface);
@@ -733,7 +869,7 @@ static int add_static_node(int *found, v
 		goto search;
 
 	if (strcmp(rec->name, targetname))
-		return 0;
+		return -1;
 
 	if (!strlen(rec->conn[0].address))
 		goto search;
@@ -751,11 +887,8 @@ static int add_static_recs(struct node_r
 	int rc, nr_found = 0;
 
 	rc = idbm_for_each_node(&nr_found, rec, add_static_node);
-	if (rc) {
-		log_error("Error while adding records. DB may be in an "
-			  "inconsistent state. Err %d", rc);
-		return rc;
-	}
+	if (rc)
+		goto done;
 	/* success */
 	if (nr_found > 0)
 		return 0;
@@ -765,13 +898,12 @@ static int add_static_recs(struct node_r
 		rc = add_static_rec(&nr_found, rec->name, rec->tpgt,
 				    rec->conn[0].address, rec->conn[0].port,
 				    &rec->iface);
-		if (rc)
-			goto done;
-		return 0;
+		if (!rc)
+			return 0;
 	}
 done:
-	printf("No records added.\n");
-	return ENODEV;
+	log_error("Error while adding record: %s", iscsi_err_to_str(rc));
+	return rc;
 }
 
 /*
@@ -799,7 +931,7 @@ static int delete_node(void *data, struc
 			  "using it. Logout session then rerun command to "
 			  "remove record.", rec->iface.name, rec->name,
 			  rec->conn[0].address, rec->conn[0].port);
-		return EINVAL;
+		return ISCSI_ERR_SESS_EXISTS;
 	}
 
 	return idbm_delete_node(rec);
@@ -822,18 +954,18 @@ static int delete_stale_rec(void *data, 
 			 * if we are not from the same discovery source
 			 * ignore it
 			 */
-			return 0;
+			return -1;
 
 		if (__iscsi_match_session(rec,
 					  new_rec->name,
 					  new_rec->conn[0].address,
 					  new_rec->conn[0].port,
-					  &new_rec->iface))
-			return 0;
+					  &new_rec->iface,
+					  new_rec->session.sid))
+			return -1;
 	}
 	/* if there is a error we can continue on */
-	delete_node(NULL, rec);
-	return 0;
+	return delete_node(NULL, rec);
 }
 
 static int
@@ -918,8 +1050,12 @@ do_software_sendtargets(discovery_rec_t 
 	rc = idbm_bind_ifaces_to_nodes(discovery_sendtargets, drec, ifaces,
 				       &rec_list);
 	if (rc) {
-		log_error("Could not perform SendTargets discovery.");
+		log_error("Could not perform SendTargets discovery: %s",
+			  iscsi_err_to_str(rc));
 		return rc;
+	} else if (list_empty(&rec_list)) {
+		log_error("No portals found");
+		return ISCSI_ERR_NO_OBJS_FOUND;
 	}
 
 	rc = exec_disc_op_on_recs(drec, &rec_list, info_level, do_login, op);
@@ -957,7 +1093,6 @@ do_sendtargets(discovery_rec_t *drec, st
 			free(iface);
 			continue;
 		}
-
 		host_no = iscsi_sysfs_get_host_no_from_hwinfo(iface, &rc);
 		if (rc || host_no == -1) {
 			log_debug(1, "Could not match iface" iface_fmt " to "
@@ -986,7 +1121,7 @@ do_sendtargets(discovery_rec_t *drec, st
 	}
 
 	if (list_empty(ifaces))
-		return ENODEV;
+		return ISCSI_ERR_NO_OBJS_FOUND;
 
 sw_st:
 	return do_software_sendtargets(drec, ifaces, info_level, do_login,
@@ -1013,8 +1148,12 @@ static int do_isns(discovery_rec_t *drec
 	rc = idbm_bind_ifaces_to_nodes(discovery_isns, drec, ifaces,
 				       &rec_list);
 	if (rc) {
-		log_error("Could not perform iSNS discovery.");
+		log_error("Could not perform iSNS discovery: %s",
+			  iscsi_err_to_str(rc));
 		return rc;
+	} else if (list_empty(&rec_list)) {
+		log_error("No portals found");
+		return ISCSI_ERR_NO_OBJS_FOUND;
 	}
 
 	rc = exec_disc_op_on_recs(drec, &rec_list, info_level, do_login, op);
@@ -1053,10 +1192,97 @@ static void catch_sigint( int signo ) {
 	exit(1);
 }
 
+static int iface_apply_net_config(struct iface_rec *iface, int op)
+{
+	int rc = ISCSI_ERR;
+	uint32_t host_no;
+	int param_count;
+	int param_used;
+	int iface_all = 0;
+	int i;
+	struct iovec *iovs = NULL;
+	struct iovec *iov = NULL;
+	struct iscsi_transport *t = NULL;
+	int fd;
+
+	log_debug(8, "Calling iscsid, to apply net config for"
+		  "iface.name = %s\n", iface->name);
+
+	if (op == OP_APPLY_ALL)
+		iface_all = 1;
+
+	param_count = iface_get_param_count(iface, iface_all);
+	if (!param_count) {
+		log_error("Nothing to configure.");
+		return ISCSI_SUCCESS;
+	}
+
+	/*
+	 * TODO: create a nicer interface where the caller does not have
+	 * know the packet/hdr details
+	 */
+
+	/* +2 for event and nlmsghdr */
+	param_count += 2;
+	iovs = calloc((param_count * sizeof(struct iovec)),
+		       sizeof(char));
+	if (!iovs) {
+		log_error("Out of Memory.");
+		return ISCSI_ERR_NOMEM;
+	}
+
+	/* param_used gives actual number of iovecs used for netconfig */
+	param_used = iface_build_net_config(iface, iface_all, iovs);
+	if (!param_used) {
+		log_error("Build netconfig failed.");
+		goto free_buf;
+	}
+
+	t = iscsi_sysfs_get_transport_by_name(iface->transport_name);
+	if (!t) {
+		log_error("Can't find transport.");
+		goto free_buf;
+	}
+
+	host_no = iscsi_sysfs_get_host_no_from_hwinfo(iface, &rc);
+	if (host_no == -1) {
+		log_error("Can't find host_no.");
+		goto free_buf;
+	}
+	rc = ISCSI_ERR;
+
+	fd = ipc->ctldev_open();
+	if (fd < 0) {
+		log_error("Netlink open failed.");
+		goto free_buf;
+	}
+
+	rc = ipc->set_net_config(t->handle, host_no, iovs, param_count);
+	if (rc < 0)
+		log_error("Set net_config failed. errno=%d", errno);
+
+	ipc->ctldev_close();
+
+free_buf:
+	/* start at 2, because 0 is for nlmsghdr and 1 for event */
+	iov = iovs + 2;
+	for (i = 0; i < param_used; i++, iov++) {
+		if (iov->iov_base)
+			free(iov->iov_base);
+	}
+
+	free(iovs);
+	if (rc)
+		return ISCSI_ERR;
+	return ISCSI_SUCCESS;
+}
+
 /* TODO: merge iter helpers and clean them up, so we can use them here */
 static int exec_iface_op(int op, int do_show, int info_level,
-			 struct iface_rec *iface, char *name, char *value)
+			 struct iface_rec *iface, uint32_t host_no,
+			 char *name, char *value)
 {
+	struct host_info hinfo;
 	struct db_set_param set_param;
 	struct node_rec *rec = NULL;
 	int rc = 0;
@@ -1071,7 +1297,7 @@ static int exec_iface_op(int op, int do_
 
 		rec = idbm_create_rec(NULL, -1, NULL, -1, iface, 0);
 		if (rec && iscsi_check_for_running_session(rec)) {
-			rc = EBUSY;
+			rc = ISCSI_ERR_SESS_EXISTS;
 			goto new_fail;
 		}
 
@@ -1088,19 +1314,19 @@ new_fail:
 		if (!iface) {
 			log_error("Could not delete interface. No interface "
 				  "passed in.");
-			return EINVAL;
+			return ISCSI_ERR_INVAL;
 		}
 
 		rec = idbm_create_rec(NULL, -1, NULL, -1, iface, 1);
 		if (!rec) {
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			goto delete_fail;
 		}
 
 		/* logout and delete records using it first */
-		rc = for_each_rec(rec, NULL, delete_node);
-		if (rc)
-			break;
+		rc = __for_each_matched_rec(0, rec, NULL, delete_node);
+		if (rc && rc != ISCSI_ERR_NO_OBJS_FOUND)
+			goto delete_fail;
 
 		rc = iface_conf_delete(iface);
 		if (rc)
@@ -1109,20 +1335,19 @@ new_fail:
 		printf("%s unbound and deleted.\n", iface->name);
 		break;
 delete_fail:
-		log_error("Could not delete iface %s. A session is "
-			  "is using it or it could not be found.",
-			   iface->name);
+		log_error("Could not delete iface %s: %s", iface->name,
+			  iscsi_err_to_str(rc));
 		break;
 	case OP_UPDATE:
 		if (!iface || !name || !value) {
 			log_error("Update requires name, value, and iface.");
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			break;
 		}
 
 		rec = idbm_create_rec(NULL, -1, NULL, -1, iface, 1);
 		if (!rec) {
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			goto update_fail;
 		}
 
@@ -1136,7 +1361,7 @@ delete_fail:
 			log_error("Can not update "
 				  "iface.iscsi_ifacename. Delete it, "
 				  "and then create a new one.");
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			break;
 		}
 
@@ -1146,7 +1371,7 @@ delete_fail:
 				  "from hwaddress to net_ifacename. ");
 			log_error("You must delete the interface and "
 				  "create a new one");
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			break;
 		}
 
@@ -1156,7 +1381,7 @@ delete_fail:
 				  "from net_ifacename to hwaddress. ");
 			log_error("You must delete the interface and "
 				  "create a new one");
-			rc = EINVAL;
+			rc = ISCSI_ERR_INVAL;
 			break;
 		}
 		set_param.name = name;
@@ -1167,23 +1392,74 @@ delete_fail:
 		if (rc)
 			goto update_fail;
 
-		rc = for_each_rec(rec, &set_param, idbm_node_set_param);
-		if (rc)
-			break;
+		rc = __for_each_matched_rec(0, rec, &set_param,
+					    idbm_node_set_param);
+		if (rc == ISCSI_ERR_NO_OBJS_FOUND)
+			rc = 0;
+		else if (rc)
+			goto update_fail;
 
 		printf("%s updated.\n", iface->name);
 		break;
 update_fail:
-		log_error("Could not update iface %s. A session is "
-			  "is using it or it could not be found.",
-			  iface->name);
+		log_error("Could not update iface %s: %s",
+			  iface->name, iscsi_err_to_str(rc));
+		break;
+	case OP_APPLY:
+		if (!iface) {
+			log_error("Apply requires iface.");
+			rc = ISCSI_ERR_INVAL;
+			break;
+		}
+		rc = iface_conf_read(iface);
+		if (rc) {
+			log_error("Could not read iface %s (%d).",
+				  iface->name, rc);
+			break;
+		}
+
+		rc = iface_apply_net_config(iface, op);
+		if (rc) {
+			log_error("Could not apply net configuration: %s",
+				  iscsi_err_to_str(rc));
+			break;
+		}
+		printf("%s applied.\n", iface->name);
+		break;
+	case OP_APPLY_ALL:
+		if (host_no == -1) {
+			log_error("Applyall requires a host number or MAC "
+				  "passed in with the --host argument.");
+			rc = ISCSI_ERR_INVAL;
+			break;
+		}
+
+		/*
+		 * Need to get other iface info like transport.
+		 */
+		memset(&hinfo, 0, sizeof(struct host_info));
+		hinfo.host_no = host_no;
+		if (iscsi_sysfs_get_hostinfo_by_host_no(&hinfo)) {
+			log_error("Could not match host%u to ifaces.", host_no);
+			rc = ISCSI_ERR_INVAL;
+			break;
+		}
+		rc = iface_apply_net_config(&hinfo.iface, op);
+		if (rc) {
+			log_error("Could not apply net configuration: %s",
+				  iscsi_err_to_str(rc));
+			break;
+		}
+
+		printf("Applied settings to ifaces attached to host%u.\n",
+		       host_no);
 		break;
 	default:
 		if (!iface || (iface && info_level > 0)) {
 			if (op == OP_NOOP || op == OP_SHOW)
 				rc = print_ifaces(iface, info_level);
 			else
-				rc = EINVAL;
+				rc = ISCSI_ERR_INVAL;
 		} else {
 			rc = iface_conf_read(iface);
 			if (!rc)
@@ -1209,38 +1485,35 @@ static int exec_node_op(int op, int do_l
 	struct db_set_param set_param;
 
 	if (rec)
-		log_debug(2, "%s: %s:%s node [%s,%s,%d]", __FUNCTION__,
+		log_debug(2, "%s: %s:%s node [%s,%s,%d] sid %u", __FUNCTION__,
 			  rec->iface.transport_name, rec->iface.name,
-			  rec->name, rec->conn[0].address, rec->conn[0].port);
+			  rec->name, rec->conn[0].address, rec->conn[0].port,
+			  rec->session.sid);
 
 	if (op == OP_NEW) {
-		if (add_static_recs(rec))
-			rc = -1;
+		rc = add_static_recs(rec);
 		goto out;
 	}
 
 	if (do_rescan) {
-		if (for_each_session(rec, rescan_portal))
-			rc = -1;
+		rc = for_each_session(rec, rescan_portal);
 		goto out;
 	}
 
 	if (do_stats) {
-		if (for_each_session(rec, session_stats))
-			rc = -1;
+		rc = for_each_session(rec, session_stats);
 		goto out;
 	}
 
 	if (do_login && do_logout) {
-		log_error("either login or logout at the time allowed!");
-		rc = -1;
+		log_error("Invalid parameters. Both login and logout passed in");
+		rc = ISCSI_ERR_INVAL;
 		goto out;
 	}
 
 	if ((do_login || do_logout) && op > OP_NOOP) {
-		log_error("either operation or login/logout "
-			  "at the time allowed!");
-		rc = -1;
+		log_error("Invalid parameters. Login/logout and op passed in");
+		rc = ISCSI_ERR_INVAL;
 		goto out;
 	}
 
@@ -1252,30 +1525,29 @@ static int exec_node_op(int op, int do_l
 	}
 
 	if (do_login) {
-		if (login_portals(rec))
-			rc = -1;
+		rc = login_portals(rec);
 		goto out;
 	}
 
 	if (do_logout) {
 		int nr_found;
 
-		if (iscsi_logout_portals(rec, &nr_found, 1,
-					 iscsi_logout_matched_portal))
-			rc = -1;
+		rc = iscsi_logout_portals(rec, &nr_found, 1,
+					  iscsi_logout_matched_portal);
+		if (rc == ISCSI_ERR_NO_OBJS_FOUND)
+			log_error("No matching sessions found");
 		goto out;
 	}
 
 	if (op == OP_NOOP || (!do_login && !do_logout && op == OP_SHOW)) {
-		if (for_each_rec(rec, &do_show, idbm_print_node_info))
-			rc = -1;
+		rc = for_each_matched_rec(rec, &do_show, idbm_print_node_info);
 		goto out;
 	}
 
 	if (op == OP_UPDATE) {
 		if (!name || !value) {
 			log_error("update requires name and value");
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -1284,7 +1556,7 @@ static int exec_node_op(int op, int do_l
 		     strcmp(name, "iface.transport_name")) {
 			log_error("Cannot modify %s. Use iface mode to update "
 				  "this value.", name);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -1304,7 +1576,7 @@ static int exec_node_op(int op, int do_l
 					    "transport name while a session "
 					    "is using it. Log out the session "
 					    "then update record.");
-				rc = -1;
+				rc = ISCSI_ERR_SESS_EXISTS;
 				goto out;
 			}
 		}
@@ -1312,16 +1584,14 @@ static int exec_node_op(int op, int do_l
 		set_param.name = name;
 		set_param.value = value;
 
-		if (for_each_rec(rec, &set_param, idbm_node_set_param))	
-			rc = -1;
+		rc = for_each_matched_rec(rec, &set_param, idbm_node_set_param);
 		goto out;
 	} else if (op == OP_DELETE) {
-		if (for_each_rec(rec, NULL, delete_node))
-			rc = -1;
+		rc = for_each_matched_rec(rec, NULL, delete_node);
 		goto out;
 	} else {
 		log_error("operation is not supported.");
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 		goto out;
 	}
 out:
@@ -1443,7 +1713,7 @@ static int exec_fw_op(discovery_rec_t *d
 			if (!rec) {
 				log_error("Could not convert firmware info to "
 					  "node record.\n");
-				rc = ENOMEM;
+				rc = ISCSI_ERR_NOMEM;
 				break;
 			}
 
@@ -1493,9 +1763,9 @@ static void setup_drec_defaults(int type
  * and will read and add a drec, and perform discovery if needed.
  *
  * returns:
- * 	-1 - error
+ * 	Greater than 0 - error
  * 	0 - op/discovery completed
- * 	1 - exec db op
+ * 	-1 - exec db op
  */
 static int exec_discover(int disc_type, char *ip, int port,
 			 struct list_head *ifaces, int info_level,
@@ -1506,15 +1776,16 @@ static int exec_discover(int disc_type, 
 
 	if (ip == NULL) {
 		log_error("Please specify portal as <ipaddr>[:<ipport>]");
-		return -1;
+		return ISCSI_ERR_INVAL;
 	}
 
 	if (op & OP_NEW && !do_discover) {
 		setup_drec_defaults(disc_type, ip, port, drec);
 
-		if (idbm_add_discovery(drec)) {
+		rc = idbm_add_discovery(drec);
+		if (rc) {
 			log_error("Could not add new discovery record.");
-			return -1;
+			return rc;
 		} else {
 			printf("New discovery record for [%s,%d] added.\n", ip,
 			       port);
@@ -1527,7 +1798,7 @@ static int exec_discover(int disc_type, 
 		if (!do_discover) {
 			log_error("Discovery record [%s,%d] not found.",
 				  ip, port);
-			return -1;
+			return rc;
 		}
 
 		/* Just add default rec for user */
@@ -1539,11 +1810,11 @@ static int exec_discover(int disc_type, 
 			if (rc) {
 				log_error("Could not add new discovery "
 					  "record.");
-				return -1;
+				return rc;
 			}
 		}
 	} else if (!do_discover)
-		return 1;
+		return -1;
 
 	rc = 0;
 	switch (disc_type) {
@@ -1563,9 +1834,7 @@ static int exec_discover(int disc_type, 
 		break;
 	}
 
-	if (rc)
-		return -1;
-	return 0;
+	return rc;
 }
 
 static int exec_disc2_op(int disc_type, char *ip, int port,
@@ -1587,12 +1856,12 @@ static int exec_disc2_op(int disc_type, 
 
 		rc = exec_discover(disc_type, ip, port, ifaces, info_level,
 				   do_login, do_discover, op, &drec);
-		if (rc == 1)
+		if (rc < 0)
 			goto do_db_op;
 		goto done;
 	case DISCOVERY_TYPE_SLP:
 		log_error("SLP discovery is not fully implemented yet.");
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 		goto done;
 	case DISCOVERY_TYPE_ISNS:
 		if (port < 0)
@@ -1600,29 +1869,30 @@ static int exec_disc2_op(int disc_type, 
 
 		rc = exec_discover(disc_type, ip, port, ifaces, info_level,
 				   do_login, do_discover, op, &drec);
-		if (rc == 1)
+		if (rc < 0)
 			goto do_db_op;
 		goto done;
 	case DISCOVERY_TYPE_FW:
 		if (!do_discover) {
 			log_error("Invalid command. Possibly missing "
 				  "--discover argument.");
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto done;
 		}
 
 		drec.type = DISCOVERY_TYPE_FW;
-		if (exec_fw_op(&drec, ifaces, info_level, do_login, op))
-			rc = -1;
+		rc = exec_fw_op(&drec, ifaces, info_level, do_login, op);
 		goto done;
 	default:
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 
 		if (!ip) {
 			 if (op == OP_NOOP || op == OP_SHOW) {
 				if (idbm_print_all_discovery(info_level))
 					/* successfully found some recs */
 					rc = 0;
+				else
+					rc = ISCSI_ERR_NO_OBJS_FOUND;
 			} else
 				log_error("Invalid operation. Operation not "
 					  "supported.");
@@ -1640,29 +1910,27 @@ do_db_op:
 
 	if (op == OP_NOOP || op == OP_SHOW) {
 		if (!idbm_print_discovery_info(&drec, do_show)) {
-			log_error("No records found!");
-			rc = -1;
+			log_error("No records found");
+			rc = ISCSI_ERR_NO_OBJS_FOUND;
 		}
 	} else if (op == OP_DELETE) {
-		if (idbm_delete_discovery(&drec)) {
+		rc = idbm_delete_discovery(&drec);
+		if (rc)
 			log_error("Unable to delete record!");
-			rc = -1;
-		}
 	} else if (op == OP_UPDATE) {
 		struct db_set_param set_param;
 
 		if (!name || !value) {
 			log_error("Update requires name and value.");
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto done;
 		}
 		set_param.name = name;
 		set_param.value = value;
-		if (idbm_discovery_set_param(&set_param, &drec))
-			rc = -1;
+		rc = idbm_discovery_set_param(&set_param, &drec);
 	} else {
 		log_error("Operation is not supported.");
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 		goto done;
 	}
 done:
@@ -1689,7 +1957,7 @@ static int exec_disc_op(int disc_type, c
 		if (ip == NULL) {
 			log_error("Please specify portal as "
 				  "<ipaddr>[:<ipport>]");
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto done;
 		}
 
@@ -1697,21 +1965,20 @@ static int exec_disc_op(int disc_type, c
 		strlcpy(drec.address, ip, sizeof(drec.address));
 		drec.port = port;
 
-		if (do_sendtargets(&drec, ifaces, info_level,
-				   do_login, op, 1)) {
-			rc = -1;
+		rc = do_sendtargets(&drec, ifaces, info_level,
+				    do_login, op, 1);
+		if (rc)
 			goto done;
-		}
 		break;
 	case DISCOVERY_TYPE_SLP:
 		log_error("SLP discovery is not fully implemented yet.");
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 		break;
 	case DISCOVERY_TYPE_ISNS:
 		if (!ip) {
 			log_error("Please specify portal as "
 				  "<ipaddr>:[<ipport>]");
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto done;
 		}
 
@@ -1721,15 +1988,13 @@ static int exec_disc_op(int disc_type, c
 		else
 			drec.port = port;
 
-		if (do_isns(&drec, ifaces, info_level, do_login, op)) {
-			rc = -1;
+		rc = do_isns(&drec, ifaces, info_level, do_login, op);
+		if (rc)
 			goto done;
-		}
 		break;
 	case DISCOVERY_TYPE_FW:
 		drec.type = DISCOVERY_TYPE_FW;
-		if (exec_fw_op(&drec, ifaces, info_level, do_login, op))
-			rc = -1;
+		rc = exec_fw_op(&drec, ifaces, info_level, do_login, op);
 		break;
 	default:
 		if (ip) {
@@ -1749,42 +2014,41 @@ static int exec_disc_op(int disc_type, c
 						ip, port)) {
 				log_error("Discovery record [%s,%d] "
 					  "not found!", ip, port);
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto done;
 			}
 			if ((do_discover || do_login) &&
 			    drec.type == DISCOVERY_TYPE_SENDTARGETS) {
-				do_sendtargets(&drec, ifaces, info_level,
-					       do_login, op, 0);
+				rc = do_sendtargets(&drec, ifaces, info_level,
+						    do_login, op, 0);
 			} else if (op == OP_NOOP || op == OP_SHOW) {
 				if (!idbm_print_discovery_info(&drec,
 							       do_show)) {
-					log_error("No records found!");
-					rc = -1;
+					log_error("No records found");
+					rc = ISCSI_ERR_NO_OBJS_FOUND;
 				}
 			} else if (op == OP_DELETE) {
-				if (idbm_delete_discovery(&drec)) {
+				rc = idbm_delete_discovery(&drec);
+				if (rc)
 					log_error("Unable to delete record!");
-					rc = -1;
-				}
 			} else if (op == OP_UPDATE || op == OP_NEW) {
 				log_error("Operations new and update for "
 					  "discovery mode is not supported. "
 					  "Use discoverydb mode.");
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto done;
 			} else {
 				log_error("Invalid operation.");
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto done;
 			}
 		} else if (op == OP_NOOP || op == OP_SHOW) {
 			if (!idbm_print_all_discovery(info_level))
-				rc = -1;
+				rc = ISCSI_ERR_NO_OBJS_FOUND;
 			goto done;
 		} else {
 			log_error("Invalid operation.");
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto done;
 		}
 		/* fall through */
@@ -1794,6 +2058,30 @@ done:
 	return rc;
 }
 
+static uint32_t parse_host_info(char *optarg, int *rc)
+{
+	int err = 0;
+	uint32_t host_no = -1;
+
+	*rc = 0;
+	if (strstr(optarg, ":")) {
+		host_no = iscsi_sysfs_get_host_no_from_hwaddress(optarg,
+								 &err);
+		if (err) {
+			log_error("Could not match MAC to host.");
+			*rc = ISCSI_ERR_INVAL;
+		}
+	} else {
+		host_no = strtoul(optarg, NULL, 10);
+		if (errno) {
+			log_error("Invalid host no %s. %s.",
+				  optarg, strerror(errno));
+			*rc = ISCSI_ERR_INVAL;
+		}
+	}
+	return host_no;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -1837,7 +2125,7 @@ main(int argc, char **argv)
 				log_error("Invalid killiscsid priority %d "
 					  "Priority must be greater than or "
 					  "equal to zero.", killiscsid);
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto free_ifaces;
 			}
 			break;
@@ -1849,7 +2137,7 @@ main(int argc, char **argv)
 			if (op == OP_NOOP) {
 				log_error("can not recognize operation: '%s'",
 					optarg);
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto free_ifaces;
 			}
 			break;
@@ -1860,21 +2148,16 @@ main(int argc, char **argv)
 			value = optarg;
 			break;
 		case 'H':
-			errno = 0;
-			host_no = strtoul(optarg, NULL, 10);
-			if (errno) {
-				log_error("invalid host no %s. %s.",
-					  optarg, strerror(errno));
-				rc = -1;
+			host_no = parse_host_info(optarg, &rc);
+			if (rc)
 				goto free_ifaces;
-			}
 			break;
 		case 'r':
 			sid = iscsi_sysfs_get_sid_from_path(optarg);
 			if (sid < 0) {
 				log_error("invalid sid '%s'",
 					  optarg);
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto free_ifaces;
 			}
 			break;
@@ -1921,15 +2204,14 @@ main(int argc, char **argv)
 			break;
 		case 'I':
 			iface = iface_alloc(optarg, &rc);
-			if (rc == EINVAL) {
+			if (rc == ISCSI_ERR_INVAL) {
 				printf("Invalid iface name %s. Must be from "
 					"1 to %d characters.\n",
 					optarg, ISCSI_MAX_IFACE_LEN - 1);
-				rc = -1;
 				goto free_ifaces;
 			} else if (!iface || rc) {
 				printf("Could not add iface %s.", optarg);
-				rc = -1;
+				rc = ISCSI_ERR_INVAL;
 				goto free_ifaces;
 			}
 
@@ -1947,7 +2229,7 @@ main(int argc, char **argv)
 
 	if (optopt) {
 		log_error("unrecognized character '%c'", optopt);
-		rc = -1;
+		rc = ISCSI_ERR_INVAL;
 		goto free_ifaces;
 	}
 
@@ -1957,13 +2239,13 @@ main(int argc, char **argv)
 	}
 
 	if (mode < 0)
-		usage(0);
+		usage(ISCSI_ERR_INVAL);
 
 	if (mode == MODE_FW) {
 		if ((rc = verify_mode_params(argc, argv, "ml", 0))) {
 			log_error("fw mode: option '-%c' is not "
 				  "allowed/supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto free_ifaces;
 		}
 
@@ -1974,7 +2256,7 @@ main(int argc, char **argv)
 	increase_max_files();
 	if (idbm_init(get_config_file)) {
 		log_warning("exiting due to idbm configuration error");
-		rc = -1;
+		rc = ISCSI_ERR_IDBM;
 		goto free_ifaces;
 	}
 
@@ -1983,7 +2265,7 @@ main(int argc, char **argv)
 		if ((rc = verify_mode_params(argc, argv, "HdmP", 0))) {
 			log_error("host mode: option '-%c' is not "
 				  "allowed/supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -1992,10 +2274,10 @@ main(int argc, char **argv)
 	case MODE_IFACE:
 		iface_setup_host_bindings();
 
-		if ((rc = verify_mode_params(argc, argv, "IdnvmPo", 0))) {
+		if ((rc = verify_mode_params(argc, argv, "HIdnvmPo", 0))) {
 			log_error("iface mode: option '-%c' is not "
 				  "allowed/supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -2007,14 +2289,14 @@ main(int argc, char **argv)
 					  "interface. Using the first one "
 					  "%s.", iface->name);
 		}
-		rc = exec_iface_op(op, do_show, info_level, iface,
+		rc = exec_iface_op(op, do_show, info_level, iface, host_no,
 				   name, value);
 		break;
 	case MODE_DISCOVERYDB:
 		if ((rc = verify_mode_params(argc, argv, "DSIPdmntplov", 0))) {
 			log_error("discovery mode: option '-%c' is not "
 				  "allowed/supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -2026,7 +2308,7 @@ main(int argc, char **argv)
 		if ((rc = verify_mode_params(argc, argv, "DSIPdmntplov", 0))) {
 			log_error("discovery mode: option '-%c' is not "
 				  "allowed/supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -2039,7 +2321,7 @@ main(int argc, char **argv)
 					     0))) {
 			log_error("node mode: option '-%c' is not "
 				  "allowed/supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 
@@ -2069,7 +2351,7 @@ main(int argc, char **argv)
 
 		rec = idbm_create_rec(targetname, tpgt, ip, port, iface, 1);
 		if (!rec) {
-			rc = -1;
+			rc = ISCSI_ERR_NOMEM;
 			goto out;
 		}
 
@@ -2082,7 +2364,7 @@ main(int argc, char **argv)
 					      "PiRdrmusonuSv", 1))) {
 			log_error("session mode: option '-%c' is not "
 				  "allowed or supported", rc);
-			rc = -1;
+			rc = ISCSI_ERR_INVAL;
 			goto out;
 		}
 		if (sid >= 0) {
@@ -2094,7 +2376,7 @@ main(int argc, char **argv)
 
 			info = calloc(1, sizeof(*info));
 			if (!info) {
-				rc = ENOMEM;
+				rc = ISCSI_ERR_NOMEM;
 				goto out;
 			}
 
@@ -2115,9 +2397,8 @@ main(int argc, char **argv)
 
 			if (!do_logout && !do_rescan && !do_stats &&
 			    op == OP_NOOP && info_level > 0) {
-				rc = session_info_print(info_level, info);
-				if (rc)
-					rc = -1;
+				rc = session_info_print(info_level, info,
+							do_show);
 				goto free_info;
 			}
 
@@ -2127,9 +2408,21 @@ main(int argc, char **argv)
 					      info->persistent_port,
 					      &info->iface, 1);
 			if (!rec) {
-				rc = -1;
+				rc = ISCSI_ERR_NOMEM;
 				goto free_info;
 			}
+			rec->session.info = info;
+			rec->session.sid = sid;
+
+			/*
+			 * A "new" session means to login a multiple of the
+			 * currently-detected session.
+			 */
+			if (op == OP_NEW) {
+				op = OP_NOOP;
+				do_login = 1;
+				rec->session.multiple = 1;
+			}
 
 			/* drop down to node ops */
 			rc = exec_node_op(op, do_login, do_logout, do_show,
@@ -2139,6 +2432,12 @@ free_info:
 			free(info);
 			goto out;
 		} else {
+			if (op == OP_NEW) {
+				log_error("session mode: Operation 'new' only "
+					  "allowed with specific session IDs");
+				rc = ISCSI_ERR_INVAL;
+				goto out;
+			}
 			if (do_logout || do_rescan || do_stats) {
 				rc = exec_node_op(op, do_login, do_logout,
 						 do_show, do_rescan, do_stats,
@@ -2146,7 +2445,7 @@ free_info:
 				goto out;
 			}
 
-			rc = session_info_print(info_level, NULL);
+			rc = session_info_print(info_level, NULL, do_show);
 		}
 		break;
 	default:
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid.c	2011-08-14 16:48:25.000000000 -0500
@@ -31,6 +31,8 @@
 #include <sys/utsname.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "iscsid.h"
 #include "mgmt_ipc.h"
@@ -48,16 +50,17 @@
 #include "sysdeps.h"
 #include "discoveryd.h"
 #include "iscsid_req.h"
+#include "iscsi_err.h"
 
 /* global config info */
 struct iscsi_daemon_config daemon_config;
 struct iscsi_daemon_config *dconfig = &daemon_config;
 
 static char program_name[] = "iscsid";
-int control_fd, mgmt_ipc_fd;
 static pid_t log_pid;
 static gid_t gid;
 static int daemonize = 1;
+static int mgmt_ipc_fd;
 
 static struct option const long_options[] = {
 	{"config", required_argument, NULL, 'c'},
@@ -66,6 +69,7 @@ static struct option const long_options[
 	{"debug", required_argument, NULL, 'd'},
 	{"uid", required_argument, NULL, 'u'},
 	{"gid", required_argument, NULL, 'g'},
+	{"no-pid-file", no_argument, NULL, 'n'},
 	{"pid", required_argument, NULL, 'p'},
 	{"help", no_argument, NULL, 'h'},
 	{"version", no_argument, NULL, 'v'},
@@ -87,12 +91,13 @@ Open-iSCSI initiator daemon.\n\
   -d, --debug debuglevel  print debugging information\n\
   -u, --uid=uid           run as uid, default is current user\n\
   -g, --gid=gid           run as gid, default is current user group\n\
+  -n, --no-pid-file       do not use a pid file\n\
   -p, --pid=pidfile       use pid file (default " PID_FILE ").\n\
   -h, --help              display this help and exit\n\
   -v, --version           display version and exit\n\
 ");
 	}
-	exit(status == 0 ? 0 : -1);
+	exit(status);
 }
 
 static void
@@ -196,11 +201,6 @@ static int sync_session(void *data, stru
 	t = iscsi_sysfs_get_transport_by_sid(info->sid);
 	if (!t)
 		return 0;
-	if (set_transport_template(t)) {
-		log_error("Could not find userspace transport template for %s",
-			   t->name);
-		return 0;
-	}
 
 	/*
 	 * Just rescan the device in case this is the first startup.
@@ -213,7 +213,8 @@ static int sync_session(void *data, stru
 		host_no = iscsi_sysfs_get_host_no_from_sid(info->sid, &err);
 		if (err) {
 			log_error("Could not get host no from sid %u. Can not "
-				  "sync session. Error %d", info->sid, err);
+				  "sync session: %s", info->sid,
+				  iscsi_err_to_str(err));
 			return 0;
 		}
 		iscsi_sysfs_scan_host(host_no, 0);
@@ -272,7 +273,7 @@ static int sync_session(void *data, stru
 
 retry:
 	rc = iscsid_exec_req(&req, &rsp, 0);
-	if (rc == MGMT_IPC_ERR_ISCSID_NOTCONN && retries < 30) {
+	if (rc == ISCSI_ERR_ISCSID_NOTCONN && retries < 30) {
 		retries++;
 		sleep(1);
 		goto retry;
@@ -302,7 +303,12 @@ static void iscsid_shutdown(void)
 
 static void catch_signal(int signo)
 {
-	log_debug(1, "%d caught signal -%d...", signo, getpid());
+	log_debug(1, "pid %d caught signal %d", getpid(), signo);
+
+	/* In foreground mode, treat SIGINT like SIGTERM */
+	if (!daemonize && signo == SIGINT)
+		signo = SIGTERM;
+
 	switch (signo) {
 	case SIGTERM:
 		iscsid_shutdown();
@@ -318,7 +324,7 @@ static void missing_iname_warn(char *ini
 	log_error("Warning: InitiatorName file %s does not exist or does not "
 		  "contain a properly formated InitiatorName. If using "
 		  "software iscsi (iscsi_tcp or ib_iser) or partial offload "
-		  "(bnx2i or cxgb3i iscsi), you may not be able to log "
+		  "(bnx2i or cxgbi iscsi), you may not be able to log "
 		  "into or discover targets. Please create a file %s that "
 		  "contains a sting with the format: InitiatorName="
 		  "iqn.yyyy-mm.<reversed domain name>[:identifier].\n\n"
@@ -337,17 +343,10 @@ int main(int argc, char *argv[])
 	uid_t uid = 0;
 	struct sigaction sa_old;
 	struct sigaction sa_new;
+	int control_fd;
 	pid_t pid;
 
-	/* do not allow ctrl-c for now... */
-	sa_new.sa_handler = catch_signal;
-	sigemptyset(&sa_new.sa_mask);
-	sa_new.sa_flags = 0;
-	sigaction(SIGINT, &sa_new, &sa_old );
-	sigaction(SIGPIPE, &sa_new, &sa_old );
-	sigaction(SIGTERM, &sa_new, &sa_old );
-
-	while ((ch = getopt_long(argc, argv, "c:i:fd:u:g:p:vh", long_options,
+	while ((ch = getopt_long(argc, argv, "c:i:fd:nu:g:p:vh", long_options,
 				 &longindex)) >= 0) {
 		switch (ch) {
 		case 'c':
@@ -368,6 +367,9 @@ int main(int argc, char *argv[])
 		case 'g':
 			gid = strtoul(optarg, NULL, 10);
 			break;
+		case 'n':
+			pid_file = NULL;
+			break;
 		case 'p':
 			pid_file = optarg;
 			break;
@@ -388,17 +390,25 @@ int main(int argc, char *argv[])
 	log_pid = log_init(program_name, DEFAULT_AREA_SIZE,
 		      daemonize ? log_do_log_daemon : log_do_log_std, NULL);
 	if (log_pid < 0)
-		exit(1);
+		exit(ISCSI_ERR);
+
+	/* do not allow ctrl-c for now... */
+	sa_new.sa_handler = catch_signal;
+	sigemptyset(&sa_new.sa_mask);
+	sa_new.sa_flags = 0;
+	sigaction(SIGINT, &sa_new, &sa_old );
+	sigaction(SIGPIPE, &sa_new, &sa_old );
+	sigaction(SIGTERM, &sa_new, &sa_old );
 
 	sysfs_init();
 	if (idbm_init(iscsid_get_config_file)) {
 		log_close(log_pid);
-		exit(1);
+		exit(ISCSI_ERR);
 	}
 
 	if (iscsi_sysfs_check_class_version()) {
 		log_close(log_pid);
-		exit(1);
+		exit(ISCSI_ERR);
 	}
 
 	umask(0177);
@@ -410,24 +420,26 @@ int main(int argc, char *argv[])
 
 	if ((mgmt_ipc_fd = mgmt_ipc_listen()) < 0) {
 		log_close(log_pid);
-		exit(1);
+		exit(ISCSI_ERR);
 	}
 
 	if (daemonize) {
 		char buf[64];
-		int fd;
+		int fd = -1;
 
-		fd = open(pid_file, O_WRONLY|O_CREAT, 0644);
-		if (fd < 0) {
-			log_error("Unable to create pid file");
-			log_close(log_pid);
-			exit(1);
+		if (pid_file) {
+			fd = open(pid_file, O_WRONLY|O_CREAT, 0644);
+			if (fd < 0) {
+				log_error("Unable to create pid file");
+				log_close(log_pid);
+				exit(ISCSI_ERR);
+			}
 		}
 		pid = fork();
 		if (pid < 0) {
 			log_error("Starting daemon failed");
 			log_close(log_pid);
-			exit(1);
+			exit(ISCSI_ERR);
 		} else if (pid) {
 			log_error("iSCSI daemon with pid=%d started!", pid);
 			exit(0);
@@ -435,18 +447,29 @@ int main(int argc, char *argv[])
 
 		if ((control_fd = ipc->ctldev_open()) < 0) {
 			log_close(log_pid);
-			exit(1);
+			exit(ISCSI_ERR);
 		}
 
-		chdir("/");
-		if (lockf(fd, F_TLOCK, 0) < 0) {
-			log_error("Unable to lock pid file");
-			log_close(log_pid);
-			exit(1);
+		if (chdir("/") < 0)
+			log_debug(1, "Unable to chdir to /");
+		if (fd > 0) {
+			if (lockf(fd, F_TLOCK, 0) < 0) {
+				log_error("Unable to lock pid file");
+				log_close(log_pid);
+				exit(ISCSI_ERR);
+			}
+			if (ftruncate(fd, 0) < 0) {
+				log_error("Unable to truncate pid file");
+				log_close(log_pid);
+				exit(ISCSI_ERR);
+			}
+			sprintf(buf, "%d\n", getpid());
+			if (write(fd, buf, strlen(buf)) < 0) {
+				log_error("Unable to write pid file");
+				log_close(log_pid);
+				exit(ISCSI_ERR);
+			}
 		}
-		ftruncate(fd, 0);
-		sprintf(buf, "%d\n", getpid());
-		write(fd, buf, strlen(buf));
 
 		daemon_init();
 	} else {
@@ -498,6 +521,7 @@ int main(int argc, char *argv[])
 	} else
 		reap_inc();
 
+	iscsi_initiator_init();
 	increase_max_files();
 	discoveryd_start(daemon_config.initiator_name);
 
@@ -509,7 +533,7 @@ int main(int argc, char *argv[])
 	if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
 		log_error("failed to mlockall, exiting...");
 		log_close(log_pid);
-		exit(1);
+		exit(ISCSI_ERR);
 	}
 
 	actor_init();
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid.h	2011-08-14 16:48:25.000000000 -0500
@@ -31,6 +31,5 @@ struct iscsi_daemon_config {
 	char *initiator_alias;
 };
 extern struct iscsi_daemon_config *dconfig;
-extern int control_fd;
 
 #endif	/* ISCSID_H */
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid_req.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid_req.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid_req.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid_req.c	2011-08-14 16:48:25.000000000 -0500
@@ -31,6 +31,7 @@
 #include "mgmt_ipc.h"
 #include "iscsi_util.h"
 #include "config.h"
+#include "iscsi_err.h"
 
 static void iscsid_startup(void)
 {
@@ -46,12 +47,14 @@ static void iscsid_startup(void)
 		return;
 	}
 
-	system(startup_cmd);
+	if (system(startup_cmd) < 0)
+		log_error("Could not execute '%s' (err %d)",
+			  startup_cmd, errno);
 }
 
 #define MAXSLEEP 128
 
-static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid)
+static int iscsid_connect(int *fd, int start_iscsid)
 {
 	int nsec;
 	struct sockaddr_un addr;
@@ -59,7 +62,7 @@ static mgmt_ipc_err_e iscsid_connect(int
 	*fd = socket(AF_LOCAL, SOCK_STREAM, 0);
 	if (*fd < 0) {
 		log_error("can not create IPC socket (%d)!", errno);
-		return MGMT_IPC_ERR_ISCSID_NOTCONN;
+		return ISCSI_ERR_ISCSID_NOTCONN;
 	}
 
 	memset(&addr, 0, sizeof(addr));
@@ -72,7 +75,7 @@ static mgmt_ipc_err_e iscsid_connect(int
 	for (nsec = 1; nsec <= MAXSLEEP; nsec <<= 1) {
 		if (connect(*fd, (struct sockaddr *) &addr, sizeof(addr)) == 0)
 			/* Connection established */
-			return MGMT_IPC_OK;
+			return ISCSI_SUCCESS;
 
 		/* If iscsid isn't there, there's no sense
 		 * in retrying. */
@@ -90,10 +93,10 @@ static mgmt_ipc_err_e iscsid_connect(int
 			sleep(nsec);
 	}
 	log_error("can not connect to iSCSI daemon (%d)!", errno);
-	return MGMT_IPC_ERR_ISCSID_NOTCONN;
+	return ISCSI_ERR_ISCSID_NOTCONN;
 }
 
-mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid)
+int iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid)
 {
 	int err;
 
@@ -105,33 +108,33 @@ mgmt_ipc_err_e iscsid_request(int *fd, i
 		log_error("got write error (%d/%d) on cmd %d, daemon died?",
 			err, errno, req->command);
 		close(*fd);
-		return MGMT_IPC_ERR_ISCSID_COMM_ERR;
+		return ISCSI_ERR_ISCSID_COMM_ERR;
 	}
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-mgmt_ipc_err_e iscsid_response(int fd, iscsiadm_cmd_e cmd, iscsiadm_rsp_t *rsp)
+int iscsid_response(int fd, iscsiadm_cmd_e cmd, iscsiadm_rsp_t *rsp)
 {
-	mgmt_ipc_err_e iscsi_err;
+	int iscsi_err;
 	int err;
 
 	if ((err = recv(fd, rsp, sizeof(*rsp), MSG_WAITALL)) != sizeof(*rsp)) {
 		log_error("got read error (%d/%d), daemon died?", err, errno);
-		iscsi_err = MGMT_IPC_ERR_ISCSID_COMM_ERR;
+		iscsi_err = ISCSI_ERR_ISCSID_COMM_ERR;
 	} else
 		iscsi_err = rsp->err;
 	close(fd);
 
 	if (!iscsi_err && cmd != rsp->command)
-		iscsi_err = MGMT_IPC_ERR_ISCSID_COMM_ERR;
+		iscsi_err = ISCSI_ERR_ISCSID_COMM_ERR;
 	return iscsi_err;
 }
 
-mgmt_ipc_err_e iscsid_exec_req(iscsiadm_req_t *req, iscsiadm_rsp_t *rsp,
+int iscsid_exec_req(iscsiadm_req_t *req, iscsiadm_rsp_t *rsp,
 				int start_iscsid)
 {
 	int fd;
-	mgmt_ipc_err_e err;
+	int err;
 
 	err = iscsid_request(&fd, req, start_iscsid);
 	if (err)
@@ -189,31 +192,3 @@ int iscsid_req_by_sid(iscsiadm_cmd_e cmd
 		return err;
 	return iscsid_req_wait(cmd, fd);
 }
-
-void iscsid_handle_error(mgmt_ipc_err_e err)
-{
-	static char *err_msgs[] = {
-		/* 0 */ "",
-		/* 1 */ "unknown error",
-		/* 2 */ "not found",
-		/* 3 */ "no available memory",
-		/* 4 */ "encountered connection failure",
-		/* 5 */ "encountered iSCSI login failure",
-		/* 6 */ "encountered iSCSI database failure",
-		/* 7 */ "invalid parameter",
-		/* 8 */ "connection timed out",
-		/* 9 */ "internal error",
-		/* 10 */ "encountered iSCSI logout failure",
-		/* 11 */ "iSCSI PDU timed out",
-		/* 12 */ "iSCSI driver not found. Please make sure it is loaded, and retry the operation",
-		/* 13 */ "daemon access denied",
-		/* 14 */ "iSCSI driver does not support requested capability.",
-		/* 15 */ "already exists",
-		/* 16 */ "Unknown request",
-		/* 17 */ "encountered iSNS failure",
-		/* 18 */ "could not communicate to iscsid",
-		/* 19 */ "encountered non-retryable iSCSI login failure",
-		/* 20 */ "could not connect to iscsid",
-	};
-	log_error("initiator reported error (%d - %s)", err, err_msgs[err]);
-}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid_req.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid_req.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsid_req.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsid_req.h	2011-08-14 16:48:25.000000000 -0500
@@ -27,7 +27,6 @@ struct node_rec;
 
 extern int iscsid_exec_req(struct iscsiadm_req *req, struct iscsiadm_rsp *rsp,
 			   int iscsid_start);
-extern void iscsid_handle_error(int err);
 extern int iscsid_req_wait(int cmd, int fd);
 extern int iscsid_req_by_rec_async(int cmd, struct node_rec *rec, int *fd);
 extern int iscsid_req_by_rec(int cmd, struct node_rec *rec);
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_err.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_err.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_err.c	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_err.c	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,72 @@
+/*
+ * iSCSI error helpers
+ *
+ * Copyright (C) 2011 Mike Christie
+ * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+ * maintained by open-iscsi@googlegroups.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * See the file COPYING included with this distribution for more details.
+ */
+#include "stdlib.h"
+#include "iscsi_err.h"
+#include "log.h"
+
+static char *iscsi_err_msgs[] = {
+	/* 0 */ "",
+	/* 1 */ "unknown error",
+	/* 2 */ "session not found",
+	/* 3 */ "no available memory",
+	/* 4 */ "encountered connection failure",
+	/* 5 */ "encountered iSCSI login failure",
+	/* 6 */ "encountered iSCSI database failure",
+	/* 7 */ "invalid parameter",
+	/* 8 */ "connection timed out",
+	/* 9 */ "internal error",
+	/* 10 */ "encountered iSCSI logout failure",
+	/* 11 */ "iSCSI PDU timed out",
+	/* 12 */ "iSCSI driver not found. Please make sure it is loaded, and retry the operation",
+	/* 13 */ "daemon access denied",
+	/* 14 */ "iSCSI driver does not support requested capability.",
+	/* 15 */ "session exists",
+	/* 16 */ "Unknown request",
+	/* 17 */ "iSNS service not supported",
+	/* 18 */ "could not communicate to iscsid",
+	/* 19 */ "encountered non-retryable iSCSI login failure",
+	/* 20 */ "could not connect to iscsid",
+	/* 21 */ "no objects found",
+	/* 22 */ "sysfs lookup failure",
+	/* 23 */ "host not found",
+	/* 24 */ "iSCSI login failed due to authorization failure",
+	/* 25 */ "iSNS query failed",
+	/* 26 */ "iSNS registration failed",
+};
+
+char *iscsi_err_to_str(int err)
+{
+	if (err >= ISCSI_MAX_ERR_VAL || err < 0) {
+		log_error("invalid error code %d", err);
+		return NULL;
+	}
+
+	return iscsi_err_msgs[err];
+}
+
+void iscsi_err_print_msg(int err)
+{
+	if (err >= ISCSI_MAX_ERR_VAL || err < 0) {
+		log_error("invalid error code %d", err);
+		return;
+	}
+	log_error("initiator reported error (%d - %s)", err,
+		  iscsi_err_msgs[err]);
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_ipc.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_ipc.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_ipc.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_ipc.h	2011-08-14 16:48:25.000000000 -0500
@@ -34,6 +34,26 @@ enum {
 };
 
 struct iscsi_conn;
+struct iscsi_ev_context;
+
+/*
+ * When handling async events, the initiator may not be able to
+ * handle the event in the same context, so this allows the interface
+ * code to call into the initiator to shedule handling.
+ */
+struct iscsi_ipc_ev_clbk {
+	void (*create_session) (uint32_t host_no, uint32_t sid);
+	void (*destroy_session) (uint32_t host_no, uint32_t sid);
+
+	struct iscsi_ev_context *(*get_ev_context) (struct iscsi_conn *conn,
+						    int ev_size);
+	void (*put_ev_context) (struct iscsi_ev_context *ev_context);
+	int (*sched_ev_context) (struct iscsi_ev_context *ev_context,
+				 struct iscsi_conn *conn,
+				 unsigned long tmo, int event);
+};
+
+extern void ipc_register_ev_callback(struct iscsi_ipc_ev_clbk *ipc_ev_clbk);
 
 /**
  * struct iscsi_ipc - Open-iSCSI Interface for Kernel IPC
@@ -109,6 +129,11 @@ struct iscsi_ipc {
 	int (*recv_pdu_begin) (struct iscsi_conn *conn);
 
 	int (*recv_pdu_end) (struct iscsi_conn *conn);
+
+	int (*set_net_config) (uint64_t transport_handle, uint32_t host_no,
+			       struct iovec *iovs, uint32_t param_count);
+
+	int (*recv_conn_state) (struct iscsi_conn *conn, uint32_t *state);
 };
 
 #endif /* ISCSI_IPC_H */
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_net_util.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_net_util.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_net_util.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_net_util.c	2011-08-14 16:48:25.000000000 -0500
@@ -41,6 +41,7 @@ struct iscsi_net_driver {
 static struct iscsi_net_driver net_drivers[] = {
 #ifdef OFFLOAD_BOOT_SUPPORTED
 	{"cxgb3", "cxgb3i" },
+	{"cxgb4", "cxgb4i" },
 	{"bnx2", "bnx2i" },
 	{"bnx2x", "bnx2i"},
 #endif
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsistart.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsistart.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsistart.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsistart.c	2011-08-14 16:48:25.000000000 -0500
@@ -47,6 +47,7 @@
 #include "iface.h"
 #include "sysdeps.h"
 #include "iscsid_req.h"
+#include "iscsi_err.h"
 
 /* global config info */
 /* initiator needs initiator name/alias */
@@ -57,10 +58,8 @@ static node_rec_t config_rec;
 static LIST_HEAD(targets);
 
 static char program_name[] = "iscsistart";
-static int mgmt_ipc_fd;
 
 /* used by initiator */
-int control_fd;
 extern struct iscsi_ipc *ipc;
 
 static struct option const long_options[] = {
@@ -108,7 +107,7 @@ Open-iSCSI initiator.\n\
   -v, --version            display version and exit\n\
 ");
 	}
-	exit(status == 0 ? 0 : -1);
+	exit(status);
 }
 
 static int stop_event_loop(void)
@@ -121,7 +120,7 @@ static int stop_event_loop(void)
 	req.command = MGMT_IPC_IMMEDIATE_STOP;
 	rc = iscsid_exec_req(&req, &rsp, 0);
 	if (rc) {
-		iscsid_handle_error(rc);
+		iscsi_err_print_msg(rc);
 		log_error("Could not stop event_loop\n");
 	}
 	return rc;
@@ -155,12 +154,12 @@ retry:
 	 * handle race where iscsid proc is starting up while we are
 	 * trying to connect.
 	 */
-	if (rc == MGMT_IPC_ERR_ISCSID_NOTCONN && retries < 30) {
+	if (rc == ISCSI_ERR_ISCSID_NOTCONN && retries < 30) {
 		retries++;
 		sleep(1);
 		goto retry;
 	} else if (rc)
-		iscsid_handle_error(rc);
+		iscsi_err_print_msg(rc);
 	return rc;
 }
 
@@ -229,7 +228,7 @@ do {									\
 	if (strlen(str) > max_len) {					\
 		printf("%s: invalid %s %s. Max %s length is %d.\n",	\
 			program_name, param, str, param, max_len);	\
-		exit(1);						\
+		exit(ISCSI_ERR_INVAL);					\
 	}								\
 } while (0);
 
@@ -242,6 +241,7 @@ int main(int argc, char *argv[])
 	struct boot_context *context, boot_context;
 	struct sigaction sa_old;
 	struct sigaction sa_new;
+	int control_fd, mgmt_ipc_fd;
 	pid_t pid;
 
 	idbm_node_setup_defaults(&config_rec);
@@ -260,7 +260,7 @@ int main(int argc, char *argv[])
 
 	sysfs_init();
 	if (iscsi_sysfs_check_class_version())
-		exit(1);
+		exit(ISCSI_ERR_SYSFS_LOOKUP);
 
 	while ((ch = getopt_long(argc, argv, "i:t:g:a:p:d:u:w:U:W:bNfvh",
 				 long_options, &longindex)) >= 0) {
@@ -316,25 +316,24 @@ int main(int argc, char *argv[])
 			ret = fw_get_entry(&boot_context);
 			if (ret) {
 				printf("Could not get boot entry.\n");
-				exit(1);
+				exit(ret);
 			}
 
 			initiatorname = boot_context.initiatorname;
 			ret = fw_get_targets(&targets);
 			if (ret || list_empty(&targets)) {
 				printf("Could not setup fw entries.\n");
-				exit(1);
+				exit(ret);
 			}
 			break;
 		case 'N':
-			ret = fw_setup_nics();
-			exit(ret);
+			exit(fw_setup_nics());
 		case 'f':
 			ret = fw_get_targets(&targets);
 			if (ret || list_empty(&targets)) {
 				printf("Could not get list of targets from "
 				       "firmware.\n");
-				exit(1);
+				exit(ret);
 			}
 
 			list_for_each_entry(context, &targets, list)
@@ -350,18 +349,18 @@ int main(int argc, char *argv[])
 			usage(0);
 			break;
 		default:
-			usage(1);
+			usage(ISCSI_ERR_INVAL);
 			break;
 		}
 	}
 
 	if (list_empty(&targets) && check_params(initiatorname))
-		exit(1);
+		exit(ISCSI_ERR_INVAL);
 
 	pid = fork();
 	if (pid < 0) {
 		log_error("iscsiboot fork failed");
-		exit(1);
+		exit(ISCSI_ERR_NOMEM);
 	} else if (pid) {
 		int status, rc, rc2;
 
@@ -376,7 +375,7 @@ int main(int argc, char *argv[])
 
 		waitpid(pid, &status, WUNTRACED);
 		if (rc || rc2)
-			exit(-1);
+			exit(ISCSI_ERR);
 
 		log_debug(1, "iscsi parent done");
 		exit(0);
@@ -385,12 +384,12 @@ int main(int argc, char *argv[])
 	mgmt_ipc_fd = mgmt_ipc_listen();
 	if (mgmt_ipc_fd  < 0) {
 		log_error("Could not setup mgmt ipc\n");
-		exit(-1);
+		exit(ISCSI_ERR_NOMEM);
 	}
 
 	control_fd = ipc->ctldev_open();
 	if (control_fd < 0)
-		exit(-1);
+		exit(ISCSI_ERR_NOMEM);
 
 	memset(&daemon_config, 0, sizeof (daemon_config));
 	daemon_config.initiator_name = initiatorname;
@@ -420,6 +419,7 @@ int main(int argc, char *argv[])
 	/*
 	 * Start Main Event Loop
 	 */
+	iscsi_initiator_init();
 	actor_init();
 	event_loop(ipc, control_fd, mgmt_ipc_fd);
 	ipc->ctldev_close();
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_sysfs.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_sysfs.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_sysfs.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_sysfs.c	2011-08-14 16:48:25.000000000 -0500
@@ -36,6 +36,7 @@
 #include "iface.h"
 #include "session_info.h"
 #include "host.h"
+#include "iscsi_err.h"
 
 /*
  * TODO: remove the _DIR defines and search for subsys dirs like
@@ -49,6 +50,7 @@
 #define ISCSI_CONN_SUBSYS		"iscsi_connection"
 #define ISCSI_HOST_SUBSYS		"iscsi_host"
 #define ISCSI_TRANSPORT_SUBSYS		"iscsi_transport"
+#define ISCSI_IFACE_SUBSYS		"iscsi_iface"
 #define SCSI_HOST_SUBSYS		"scsi_host"
 #define SCSI_SUBSYS			"scsi"
 
@@ -115,6 +117,10 @@ static int read_transports(void)
 			INIT_LIST_HEAD(&t->list);
 			strlcpy(t->name, namelist[i]->d_name,
 				ISCSI_TRANSPORT_NAME_MAXLEN);
+			if (set_transport_template(t)) {
+				free(t);
+				return -1;
+			}
 		} else
 			log_debug(7, "Updating transport %s",
 				  namelist[i]->d_name);
@@ -143,7 +149,6 @@ static int read_transports(void)
 		 */
 		if (!strcmp(t->name, "qla4xxx")) {
 			t->caps |= CAP_DATA_PATH_OFFLOAD;
-			t->caps |= CAP_FW_DB;
 		}
 
 		if (list_empty(&t->list))
@@ -238,7 +243,7 @@ uint32_t iscsi_sysfs_get_host_no_from_si
 					       ISCSI_SESSION_SUBSYS, id)) {
 		log_error("Could not lookup devpath for %s. Possible sysfs "
 			  "incompatibility.\n", id);
-		*err = EIO;
+		*err = ISCSI_ERR_SYSFS_LOOKUP;
 		return 0;
 	}
 
@@ -246,7 +251,7 @@ uint32_t iscsi_sysfs_get_host_no_from_si
 	if (!session_dev) {
 		log_error("Could not get dev for %s. Possible sysfs "
 			  "incompatibility.\n", id);
-		*err = EIO;
+		*err = ISCSI_ERR_SYSFS_LOOKUP;
 		return 0;
 	}
 
@@ -271,7 +276,7 @@ uint32_t iscsi_sysfs_get_host_no_from_si
 		if (!host_dev) {
 			log_error("Could not get host dev for %s. Possible "
 				  "sysfs incompatibility.\n", id);
-			*err = EIO;
+			*err = ISCSI_ERR_SYSFS_LOOKUP;
 			return 0;
 		}
 	}
@@ -301,7 +306,7 @@ static uint32_t get_host_no_from_netdev(
 
 	info = calloc(1, sizeof(*info));
 	if (!info) {
-		*rc = ENOMEM;
+		*rc = ISCSI_ERR_NOMEM;
 		return -1;
 	}
 	strcpy(info->iface.netdev, netdev);
@@ -311,7 +316,7 @@ static uint32_t get_host_no_from_netdev(
 	if (local_rc == 1)
 		host_no = info->host_no;
 	else
-		*rc = ENODEV;
+		*rc = ISCSI_ERR_HOST_NOT_FOUND;
 	free(info);
 	return host_no;
 }
@@ -320,14 +325,14 @@ static int __get_host_no_from_hwaddress(
 {
 	struct host_info *ret_info = data;
 
-	if (!strcmp(ret_info->iface.hwaddress, info->iface.hwaddress)) {
+	if (!strcasecmp(ret_info->iface.hwaddress, info->iface.hwaddress)) {
 		ret_info->host_no = info->host_no;
 		return 1;
 	}
 	return 0;
 }
 
-static uint32_t get_host_no_from_hwaddress(char *address, int *rc)
+uint32_t iscsi_sysfs_get_host_no_from_hwaddress(char *hwaddress, int *rc)
 {
 	uint32_t host_no = -1;
 	struct host_info *info;
@@ -337,17 +342,17 @@ static uint32_t get_host_no_from_hwaddre
 
 	info = calloc(1, sizeof(*info));
 	if (!info) {
-		*rc = ENOMEM;
+		*rc = ISCSI_ERR_NOMEM;
 		return -1;
 	}
-	strcpy(info->iface.hwaddress, address);
+	strcpy(info->iface.hwaddress, hwaddress);
 
 	local_rc = iscsi_sysfs_for_each_host(info, &nr_found,
 					__get_host_no_from_hwaddress);
 	if (local_rc == 1)
 		host_no = info->host_no;
 	else
-		*rc = ENODEV;
+		*rc = ISCSI_ERR_HOST_NOT_FOUND;
 	free(info);
 	return host_no;
 }
@@ -374,7 +379,7 @@ static uint32_t get_host_no_from_ipaddre
 
 	info = calloc(1, sizeof(*info));
 	if (!info) {
-		*rc = ENOMEM;
+		*rc = ISCSI_ERR_NOMEM;
 		return -1;
 	}
 	strcpy(info->iface.ipaddress, address);
@@ -384,7 +389,7 @@ static uint32_t get_host_no_from_ipaddre
 	if (local_rc == 1)
 		host_no = info->host_no;
 	else
-		*rc = ENODEV;
+		*rc = ISCSI_ERR_HOST_NOT_FOUND;
 	free(info);
 	return host_no;
 }
@@ -396,7 +401,8 @@ uint32_t iscsi_sysfs_get_host_no_from_hw
 
 	if (strlen(iface->hwaddress) &&
 	    strcasecmp(iface->hwaddress, DEFAULT_HWADDRESS))
-		host_no = get_host_no_from_hwaddress(iface->hwaddress, &tmp_rc);
+		host_no = iscsi_sysfs_get_host_no_from_hwaddress(
+						iface->hwaddress, &tmp_rc);
 	else if (strlen(iface->netdev) &&
 		strcasecmp(iface->netdev, DEFAULT_NETDEV))
 		host_no = get_host_no_from_netdev(iface->netdev, &tmp_rc);
@@ -404,7 +410,7 @@ uint32_t iscsi_sysfs_get_host_no_from_hw
 		 strcasecmp(iface->ipaddress, DEFAULT_IPADDRESS))
 		host_no = get_host_no_from_ipaddress(iface->ipaddress, &tmp_rc);
 	else
-		tmp_rc = EINVAL;
+		tmp_rc = ISCSI_ERR_INVAL;
 
 	*rc = tmp_rc;
 	return host_no;
@@ -417,9 +423,9 @@ uint32_t iscsi_sysfs_get_host_no_from_hw
  * qla4xxx.
  */
 static int iscsi_sysfs_read_iface(struct iface_rec *iface, int host_no,
-				  char *session)
+				  char *session, char *iface_kern_id)
 {
-	char id[NAME_SIZE];
+	char host_id[NAME_SIZE];
 	struct iscsi_transport *t;
 	int ret;
 
@@ -430,26 +436,31 @@ static int iscsi_sysfs_read_iface(struct
 	else
 		strcpy(iface->transport_name, t->name);
 
-	snprintf(id, sizeof(id), ISCSI_HOST_ID, host_no);
+	snprintf(host_id, sizeof(host_id), ISCSI_HOST_ID, host_no);
 	/*
 	 * backward compat
 	 * If we cannot get the address we assume we are doing the old
 	 * style and use default.
 	 */
-	ret = sysfs_get_str(id, ISCSI_HOST_SUBSYS, "hwaddress",
+	ret = sysfs_get_str(host_id, ISCSI_HOST_SUBSYS, "hwaddress",
 			    iface->hwaddress, sizeof(iface->hwaddress));
 	if (ret)
 		log_debug(7, "could not read hwaddress for host%d\n", host_no);
 
-	/* if not found just print out default */
-	ret = sysfs_get_str(id, ISCSI_HOST_SUBSYS, "ipaddress",
-			    iface->ipaddress, sizeof(iface->ipaddress));
+	if (iface_kern_id)
+		ret = sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS,
+				    "ipaddress",
+				    iface->ipaddress, sizeof(iface->ipaddress));
+	else
+		/* if not found just print out default */
+		ret = sysfs_get_str(host_id, ISCSI_HOST_SUBSYS, "ipaddress",
+				    iface->ipaddress, sizeof(iface->ipaddress));
 	if (ret)
 		log_debug(7, "could not read local address for host%d\n",
 			  host_no);
 
 	/* if not found just print out default */
-	ret = sysfs_get_str(id, ISCSI_HOST_SUBSYS, "netdev",
+	ret = sysfs_get_str(host_id, ISCSI_HOST_SUBSYS, "netdev",
 			    iface->netdev, sizeof(iface->netdev));
 	if (ret)
 		log_debug(7, "could not read netdev for host%d\n", host_no);
@@ -459,7 +470,7 @@ static int iscsi_sysfs_read_iface(struct
 	 * host level because we cannot create different initiator ports
 	 * (cannot set isid either). The LLD also exports the iname at the
 	 * hba level so apps can see it, but we no longer set the iname for
-	 * each iscsid controlled host since bnx2i cxgb3i can support multiple
+	 * each iscsid controlled host since bnx2i cxgbi can support multiple
 	 * initiator names and of course software iscsi can support anything.
 	 */
 	ret = 1;
@@ -481,7 +492,7 @@ static int iscsi_sysfs_read_iface(struct
 	}
 
 	if (ret) {
-		ret = sysfs_get_str(id, ISCSI_HOST_SUBSYS, "initiatorname",
+		ret = sysfs_get_str(host_id, ISCSI_HOST_SUBSYS, "initiatorname",
 				    iface->iname, sizeof(iface->iname));
 		if (ret)
 			/*
@@ -493,6 +504,8 @@ static int iscsi_sysfs_read_iface(struct
 			 */
 			log_debug(7, "Could not read initiatorname for "
 				  "host%d\n", host_no);
+		/* optional so do not return error */
+		ret = 0;
 	}
 
 	/*
@@ -523,12 +536,63 @@ static int iscsi_sysfs_read_iface(struct
 					  iface_str(iface));
 		}
 	}
-	return ret;
+
+	if (!iface_kern_id)
+		goto done;
+
+	strlcpy(iface->name, iface_kern_id, sizeof(iface->name));
+
+	if (!strncmp(iface_kern_id, "ipv4", 4)) {
+		sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS, "bootproto",
+			      iface->bootproto, sizeof(iface->bootproto));
+
+		sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS, "gateway",
+			      iface->gateway, sizeof(iface->gateway));
+
+		sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS, "subnet",
+			      iface->subnet_mask, sizeof(iface->subnet_mask));
+	} else {
+		sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS,
+			      "ipaddr_autocfg",
+			      iface->ipv6_autocfg, sizeof(iface->ipv6_autocfg));
+
+		sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS,
+			      "link_local_addr", iface->ipv6_linklocal,
+			      sizeof(iface->ipv6_linklocal));
+
+		if (sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS,
+				  "linklocal_autocfg",
+				   iface->linklocal_autocfg,
+				   sizeof(iface->linklocal_autocfg))) {
+			/* misspelled in some test kernels */
+			sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS,
+				      "link_local_autocfg",
+				      iface->linklocal_autocfg,
+				      sizeof(iface->linklocal_autocfg));
+		}
+
+		sysfs_get_str(iface_kern_id, ISCSI_IFACE_SUBSYS, "router_addr",
+			      iface->ipv6_router,
+			      sizeof(iface->ipv6_router));
+	}
+
+	sysfs_get_uint16(iface_kern_id, ISCSI_IFACE_SUBSYS, "mtu",
+			 &iface->mtu);
+	sysfs_get_uint16(iface_kern_id, ISCSI_IFACE_SUBSYS, "vlan",
+			 &iface->vlan_id);
+	sysfs_get_uint8(iface_kern_id, ISCSI_IFACE_SUBSYS, "vlan_priority",
+			 &iface->vlan_priority);
+done:
+	if (ret)
+		return ISCSI_ERR_SYSFS_LOOKUP;
+	else
+		return 0;
 }
 
 int iscsi_sysfs_get_hostinfo_by_host_no(struct host_info *hinfo)
 {
-	return iscsi_sysfs_read_iface(&hinfo->iface, hinfo->host_no, NULL);
+	return iscsi_sysfs_read_iface(&hinfo->iface, hinfo->host_no, NULL,
+				      NULL);
 }
 
 int iscsi_sysfs_for_each_host(void *data, int *nr_found,
@@ -540,7 +604,7 @@ int iscsi_sysfs_for_each_host(void *data
 
 	info = malloc(sizeof(*info));
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	n = scandir(ISCSI_HOST_DIR, &namelist, trans_filter,
 		    alphasort);
@@ -572,6 +636,50 @@ free_info:
 	return rc;
 }
 
+int iscsi_sysfs_for_each_iface_on_host(void *data, uint32_t host_no,
+				       int *nr_found,
+				       iscsi_sysfs_iface_op_fn *fn)
+{
+	struct dirent **namelist;
+	int rc = 0, i, n;
+	struct iface_rec iface;
+        char devpath[PATH_SIZE];
+        char sysfs_path[PATH_SIZE];
+        char id[NAME_SIZE];
+
+        snprintf(id, sizeof(id), "host%u", host_no);
+        if (!sysfs_lookup_devpath_by_subsys_id(devpath, sizeof(devpath),
+                                               SCSI_SUBSYS, id)) {
+                log_error("Could not look up host's ifaces via scsi bus.");
+                return ISCSI_ERR_SYSFS_LOOKUP;
+        }
+
+	sprintf(sysfs_path, "/sys");
+	strlcat(sysfs_path, devpath, sizeof(sysfs_path));
+	strlcat(sysfs_path, "/iscsi_iface", sizeof(sysfs_path));
+
+	n = scandir(sysfs_path, &namelist, trans_filter, alphasort);
+	if (n <= 0)
+		/* older kernels or some drivers will not have ifaces */
+		return 0;
+
+	for (i = 0; i < n; i++) {
+		memset(&iface, 0, sizeof(iface));
+
+		iscsi_sysfs_read_iface(&iface, host_no, NULL,
+				       namelist[i]->d_name);
+		rc = fn(data, &iface);
+		if (rc != 0)
+			break;
+		(*nr_found)++;
+	}
+
+	for (i = 0; i < n; i++)
+		free(namelist[i]);
+	free(namelist);
+	return rc;
+}
+
 /**
  * sysfs_session_has_leadconn - checks if session has lead conn in kernel
  * @sid: session id
@@ -631,7 +739,7 @@ int iscsi_sysfs_get_sid_from_path(char *
 	if (!dev) {
 		log_error("Could not get dev for %s. Possible sysfs "
 			  "incompatibility.\n", devpath);
-		exit(1);
+		return -1;
 	}
 
 	if (!strncmp(dev->kernel, "session", 7))
@@ -645,8 +753,7 @@ int iscsi_sysfs_get_sid_from_path(char *
 	}
 
 	log_error("Unable to find sid in path %s", session);
-	exit(1);
-	return 0;
+	return -1;
 }
 
 int iscsi_sysfs_get_sessioninfo_by_id(struct session_info *info, char *session)
@@ -657,21 +764,65 @@ int iscsi_sysfs_get_sessioninfo_by_id(st
 
 	if (sscanf(session, "session%d", &info->sid) != 1) {
 		log_error("invalid session '%s'", session);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "targetname",
 			    info->targetname, sizeof(info->targetname));
 	if (ret) {
 		log_error("could not read session targetname: %d", ret);
-		return ret;
+		return ISCSI_ERR_SYSFS_LOOKUP;
 	}
 
+	ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "username",
+				(info->chap).username,
+				sizeof((info->chap).username));
+	if (ret)
+		log_debug(5, "could not read username: %d", ret);
+
+	ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "password",
+				(info->chap).password,
+				sizeof((info->chap).password));
+	if (ret)
+		log_debug(5, "could not read password: %d", ret);
+
+	ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "username_in",
+				(info->chap).username_in,
+				sizeof((info->chap).username_in));
+	if (ret)
+		log_debug(5, "could not read username in: %d", ret);
+
+	ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "password_in",
+				(info->chap).password_in,
+				sizeof((info->chap).password_in));
+	if (ret)
+		log_debug(5, "could not read password in: %d", ret);
+
+	ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "recovery_tmo",
+				&((info->tmo).recovery_tmo));
+	if (ret)
+		(info->tmo).recovery_tmo = -1;
+
+	ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "lu_reset_tmo",
+				&((info->tmo).lu_reset_tmo));
+	if (ret)
+		(info->tmo).lu_reset_tmo = -1;
+
+	ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "tgt_reset_tmo",
+				&((info->tmo).tgt_reset_tmo));
+	if (ret)
+		(info->tmo).lu_reset_tmo = -1;
+
+	sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "abort_tmo",
+				&((info->tmo).abort_tmo));
+	if (ret)
+		(info->tmo).abort_tmo = -1;
+
 	ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "tpgt",
 			    &info->tpgt);
 	if (ret) {
-		log_error("could not read session tpgt: %u", ret);
-		return ret;
+		log_error("could not read session tpgt: %d", ret);
+		return ISCSI_ERR_SYSFS_LOOKUP;
 	}
 
 	snprintf(id, sizeof(id), ISCSI_CONN_ID, info->sid);
@@ -727,13 +878,13 @@ int iscsi_sysfs_get_sessioninfo_by_id(st
 	ret = 0;
 	host_no = iscsi_sysfs_get_host_no_from_sid(info->sid, &ret);
 	if (ret) {
-		log_error("could not get host_no for session%d err %d.",
-			  info->sid, ret);
+		log_error("could not get host_no for session%d: %s.",
+			  info->sid, iscsi_err_to_str(ret));
 		return ret;
 	}
 
-	iscsi_sysfs_read_iface(&info->iface, host_no, session);
- 
+	iscsi_sysfs_read_iface(&info->iface, host_no, session, NULL);
+
 	log_debug(7, "found targetname %s address %s pers address %s port %d "
 		 "pers port %d driver %s iface name %s ipaddress %s "
 		 "netdev %s hwaddress %s iname %s",
@@ -745,7 +896,7 @@ int iscsi_sysfs_get_sessioninfo_by_id(st
 		  info->iface.iname);
 	return 0;
 }
- 
+
 int iscsi_sysfs_for_each_session(void *data, int *nr_found,
 				 iscsi_sysfs_session_op_fn *fn)
 {
@@ -755,7 +906,7 @@ int iscsi_sysfs_for_each_session(void *d
 
 	info = calloc(1, sizeof(*info));
 	if (!info)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 
 	n = scandir(ISCSI_SESSION_DIR, &namelist, trans_filter,
 		    alphasort);
@@ -797,8 +948,10 @@ int iscsi_sysfs_get_session_state(char *
 	char id[NAME_SIZE];
 
 	snprintf(id, sizeof(id), ISCSI_SESSION_ID, sid);
-	return sysfs_get_str(id, ISCSI_SESSION_SUBSYS, "state", state,
-			     SCSI_MAX_STATE_VALUE);
+	if (sysfs_get_str(id, ISCSI_SESSION_SUBSYS, "state", state,
+			  SCSI_MAX_STATE_VALUE))
+		return ISCSI_ERR_SYSFS_LOOKUP;
+	return 0;
 }
 
 int iscsi_sysfs_get_host_state(char *state, int host_no)
@@ -806,8 +959,10 @@ int iscsi_sysfs_get_host_state(char *sta
 	char id[NAME_SIZE];
 
 	snprintf(id, sizeof(id), ISCSI_HOST_ID, host_no);
-	return sysfs_get_str(id, SCSI_HOST_SUBSYS, "state", state,
-			     SCSI_MAX_STATE_VALUE);
+	if (sysfs_get_str(id, SCSI_HOST_SUBSYS, "state", state,
+			  SCSI_MAX_STATE_VALUE))
+		return ISCSI_ERR_SYSFS_LOOKUP;
+	return 0;
 }
 
 int iscsi_sysfs_get_device_state(char *state, int host_no, int target, int lun)
@@ -818,7 +973,7 @@ int iscsi_sysfs_get_device_state(char *s
 	if (sysfs_get_str(id, SCSI_SUBSYS, "state", state,
 			  SCSI_MAX_STATE_VALUE)) {
 		log_debug(3, "Could not read attr state for %s\n", id);
-		return EIO;
+		return ISCSI_ERR_SYSFS_LOOKUP;
 	}
 
 	return 0;
@@ -828,7 +983,6 @@ char *iscsi_sysfs_get_blockdev_from_lun(
 {
 	char devpath[PATH_SIZE];
 	char path_full[PATH_SIZE];
-	char *path;
 	char id[NAME_SIZE];
 	DIR *dirfd;
 	struct dirent *dent;
@@ -845,9 +999,8 @@ char *iscsi_sysfs_get_blockdev_from_lun(
 	}
 
 	sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
-	if(sysfs_len >= sizeof(path_full))
+	if (sysfs_len >= sizeof(path_full))
 		sysfs_len = sizeof(path_full) - 1;
-	path = &path_full[sysfs_len];
 	strlcat(path_full, devpath, sizeof(path_full));
 
 	dirfd = opendir(path_full);
@@ -912,14 +1065,13 @@ static uint32_t get_target_no_from_sid(u
 {
 	char devpath[PATH_SIZE];
 	char path_full[PATH_SIZE];
-	char *path;
 	char id[NAME_SIZE];
 	DIR *dirfd;
 	struct dirent *dent;
 	uint32_t host, bus, target = 0;
 	size_t sysfs_len;
 
-	*err = ENODEV;
+	*err = ISCSI_ERR_SESS_NOT_FOUND;
 
 	snprintf(id, sizeof(id), "session%u", sid);
 	if (!sysfs_lookup_devpath_by_subsys_id(devpath, sizeof(devpath),
@@ -935,9 +1087,8 @@ static uint32_t get_target_no_from_sid(u
 	 * /class/iscsi_session/sessionX/device.
 	 */
 	sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
-	if(sysfs_len >= sizeof(path_full))
+	if (sysfs_len >= sizeof(path_full))
 		sysfs_len = sizeof(path_full) - 1;
-	path = &path_full[sysfs_len];
 	strlcat(path_full, devpath, sizeof(path_full));
 	strlcat(path_full, "/device", sizeof(devpath));
 
@@ -970,7 +1121,8 @@ struct iscsi_transport *iscsi_sysfs_get_
 	struct iscsi_transport *t;
 
 	/* sync up kernel and userspace */
-	read_transports();
+	if (read_transports())
+		return NULL;
 
 	/* check if the transport is loaded and matches */
 	list_for_each_entry(t, &transports, list) {
@@ -1043,6 +1195,19 @@ int iscsi_sysfs_get_exp_statsn(int sid)
 	return exp_statsn;
 }
 
+int iscsi_sysfs_session_supports_nop(int sid)
+{
+	char id[NAME_SIZE];
+	uint32_t ping_tmo = 0;
+
+	snprintf(id, sizeof(id), ISCSI_CONN_ID, sid);
+	if (sysfs_get_uint(id, ISCSI_CONN_SUBSYS, "ping_tmo",
+			   &ping_tmo)) {
+		return 0;
+	}
+	return 1;
+}
+
 int iscsi_sysfs_for_each_device(void *data, int host_no, uint32_t sid,
 				void (* fn)(void *data, int host_no,
 					    int target, int lun))
@@ -1061,7 +1226,7 @@ int iscsi_sysfs_for_each_device(void *da
 					       ISCSI_SESSION_SUBSYS, id)) {
 		log_debug(3, "Could not lookup devpath for %s %s\n",
 			  ISCSI_SESSION_SUBSYS, id);
-		return EIO;
+		return ISCSI_ERR_SYSFS_LOOKUP;
 	}
 
 	snprintf(path_full, sizeof(path_full), "%s%s/device/target%d:0:%d",
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_sysfs.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_sysfs.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_sysfs.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_sysfs.h	2011-08-14 16:48:25.000000000 -0500
@@ -43,7 +43,11 @@ extern int iscsi_sysfs_session_has_leadc
 
 typedef int (iscsi_sysfs_session_op_fn)(void *, struct session_info *);
 typedef int (iscsi_sysfs_host_op_fn)(void *, struct host_info *);
+typedef int (iscsi_sysfs_iface_op_fn)(void *, struct iface_rec *);
 
+extern int iscsi_sysfs_for_each_iface_on_host(void *data, uint32_t host_no,
+					      int *nr_found,
+					      iscsi_sysfs_iface_op_fn *fn);
 extern int iscsi_sysfs_for_each_session(void *data, int *nr_found,
 					iscsi_sysfs_session_op_fn *fn);
 extern int iscsi_sysfs_for_each_host(void *data, int *nr_found,
@@ -51,6 +55,7 @@ extern int iscsi_sysfs_for_each_host(voi
 extern uint32_t iscsi_sysfs_get_host_no_from_sid(uint32_t sid, int *err);
 extern uint32_t iscsi_sysfs_get_host_no_from_hwinfo(struct iface_rec *iface,
 						    int *rc);
+extern uint32_t iscsi_sysfs_get_host_no_from_hwaddress(char *hwaddress, int *rc);
 extern int iscsi_sysfs_get_hostinfo_by_host_no(struct host_info *hinfo);
 extern int iscsi_sysfs_get_sid_from_path(char *session);
 extern char *iscsi_sysfs_get_blockdev_from_lun(int hostno, int target, int sid);
@@ -84,6 +89,7 @@ extern struct iscsi_transport *iscsi_sys
 extern struct iscsi_transport *iscsi_sysfs_get_transport_by_session(char *sys_session);
 extern struct iscsi_transport *iscsi_sysfs_get_transport_by_sid(uint32_t sid);
 extern struct iscsi_transport *iscsi_sysfs_get_transport_by_name(char *transport_name);
+extern int iscsi_sysfs_session_supports_nop(int sid);
 
 extern struct list_head transports;
 
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_timer.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_timer.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_timer.c	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_timer.c	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,86 @@
+/*
+ * iSCSI timer
+ *
+ * Copyright (C) 2002 Cisco Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * See the file COPYING included with this distribution for more details.
+ */
+#include <string.h>
+#include <sys/time.h>
+
+void iscsi_timer_clear(struct timeval *timer)
+{
+	memset(timer, 0, sizeof (*timer));
+}
+
+/* set timer to now + seconds */
+void iscsi_timer_set(struct timeval *timer, int seconds)
+{
+	if (timer) {
+		memset(timer, 0, sizeof (*timer));
+		gettimeofday(timer, NULL);
+
+		timer->tv_sec += seconds;
+	}
+}
+
+int iscsi_timer_expired(struct timeval *timer)
+{
+	struct timeval now;
+
+	/* no timer, can't have expired */
+	if ((timer == NULL) || ((timer->tv_sec == 0) && (timer->tv_usec == 0)))
+		return 0;
+
+	memset(&now, 0, sizeof (now));
+	gettimeofday(&now, NULL);
+
+	if (now.tv_sec > timer->tv_sec)
+		return 1;
+	if ((now.tv_sec == timer->tv_sec) && (now.tv_usec >= timer->tv_usec))
+		return 1;
+	return 0;
+}
+
+int iscsi_timer_msecs_until(struct timeval *timer)
+{
+	struct timeval now;
+	int msecs;
+	long partial;
+
+	/* no timer, can't have expired, infinite time til it expires */
+	if ((timer == NULL) || ((timer->tv_sec == 0) && (timer->tv_usec == 0)))
+		return -1;
+
+	memset(&now, 0, sizeof (now));
+	gettimeofday(&now, NULL);
+
+	/* already expired? */
+	if (now.tv_sec > timer->tv_sec)
+		return 0;
+	if ((now.tv_sec == timer->tv_sec) && (now.tv_usec >= timer->tv_usec))
+		return 0;
+
+	/* not expired yet, do the math */
+	partial = timer->tv_usec - now.tv_usec;
+	if (partial < 0) {
+		partial += 1000 * 1000;
+		msecs = (partial + 500) / 1000;
+		msecs += (timer->tv_sec - now.tv_sec - 1) * 1000;
+	} else {
+		msecs = (partial + 500) / 1000;
+		msecs += (timer->tv_sec - now.tv_sec) * 1000;
+	}
+
+	return msecs;
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_timer.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_timer.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_timer.h	1969-12-31 18:00:00.000000000 -0600
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_timer.h	2011-08-14 16:48:25.000000000 -0500
@@ -0,0 +1,28 @@
+/*
+ * iSCSI timer
+ *
+ * Copyright (C) 2002 Cisco Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * See the file COPYING included with this distribution for more details.
+ */
+#ifndef ISCSI_TIMER_H
+#define ISCSI_TIMER_H
+
+struct timeval;
+
+extern void iscsi_timer_clear(struct timeval *timer);
+extern void iscsi_timer_set(struct timeval *timer, int seconds);
+extern int iscsi_timer_expired(struct timeval *timer);
+extern int iscsi_timer_msecs_until(struct timeval *timer);
+
+#endif
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_util.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_util.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_util.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_util.c	2011-08-14 16:48:25.000000000 -0500
@@ -25,12 +25,15 @@
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/resource.h>
 
 #include "log.h"
 #include "iscsi_settings.h"
 #include "iface.h"
 #include "session_info.h"
+#include "iscsi_util.h"
 
 void daemon_init(void)
 {
@@ -45,24 +48,38 @@ void daemon_init(void)
 	dup2(fd, 1);
 	dup2(fd, 2);
 	setsid();
-	chdir("/");
+	if (chdir("/") < 0)
+		log_debug(1, "Could not chdir to /: %s", strerror(errno));
 }
 
+#define ISCSI_OOM_PATH_LEN 48
+
 int oom_adjust(void)
 {
 	int fd;
-	char path[48];
+	char path[ISCSI_OOM_PATH_LEN];
+	struct stat statb;
 
-	nice(-10);
-	sprintf(path, "/proc/%d/oom_adj", getpid());
+	if (nice(-10) < 0)
+		log_debug(1, "Could not increase process priority: %s",
+			  strerror(errno));
+
+	snprintf(path, ISCSI_OOM_PATH_LEN, "/proc/%d/oom_score_adj", getpid());
+	if (stat(path, &statb)) {
+		/* older kernel so use old oom_adj file */
+		snprintf(path, ISCSI_OOM_PATH_LEN, "/proc/%d/oom_adj",
+			 getpid());
+	}
 	fd = open(path, O_WRONLY);
-	if (fd < 0) {
+	if (fd < 0)
 		return -1;
-	}
-	write(fd, "-16\n", 3); /* for 2.6.11 */
-	write(fd, "-17\n", 3); /* for Andrea's patch */
+	if (write(fd, "-16", 3) < 0) /* for 2.6.11 */
+		log_debug(1, "Could not set oom score to -16: %s",
+			  strerror(errno));
+	if (write(fd, "-17", 3) < 0) /* for Andrea's patch */
+		log_debug(1, "Could not set oom score to -17: %s",
+			  strerror(errno));
 	close(fd);
-
 	return 0;
 }
 
@@ -217,31 +234,92 @@ char *cfg_get_string_param(char *pathnam
 	return value;
 }
 
+/**
+ * iscsi_addr_match - check if the addrs are to the same ip
+ * @address1: pattern
+ * @address2: address to check
+ *
+ * If address1 is blank then it matches any string passed in.
+ */
+static int iscsi_addr_match(char *address1, char *address2)
+{
+	struct addrinfo hints1, hints2, *res1, *res2;
+	int rc;
+
+	if (!strlen(address1))
+		return 1;
+
+	if (!strcmp(address1, address2))
+		return 1;
+
+	memset(&hints1, 0, sizeof(struct addrinfo));
+	hints1.ai_family = AF_UNSPEC;
+	hints1.ai_socktype = SOCK_STREAM;
+
+	memset(&hints2, 0, sizeof(struct addrinfo));
+	hints2.ai_family = AF_UNSPEC;
+	hints2.ai_socktype = SOCK_STREAM;
+
+	/*
+	 * didn't match so we have to resolve to see if one is a dnsname
+	 * that matches a ip address.
+	 */
+	rc = getaddrinfo(address1, NULL, &hints1, &res1);
+	if (rc) {
+		log_debug(1, "Match error. Could not resolve %s: %s", address1,
+			  gai_strerror(rc));
+		return 0;
+
+	}
+
+	rc = getaddrinfo(address2, NULL, &hints2, &res2);
+	if (rc) {
+		log_debug(1, "Match error. Could not resolve %s: %s", address2,
+			  gai_strerror(rc));
+		rc = 0;
+		goto free_res1;
+	}
+
+	if ((res1->ai_addrlen != res2->ai_addrlen) ||
+	    memcmp(res1->ai_addr, res2->ai_addr, res2->ai_addrlen))
+		rc = 0;
+	else
+		rc = 1;
+
+	freeaddrinfo(res2);
+free_res1:
+	freeaddrinfo(res1);
+	return rc;
+}
+
 int __iscsi_match_session(node_rec_t *rec, char *targetname,
-			  char *address, int port, struct iface_rec *iface)
+			  char *address, int port, struct iface_rec *iface,
+			  unsigned sid)
 {
 	if (!rec) {
 		log_debug(6, "no rec info to match\n");
 		return 1;
 	}
 
-	log_debug(6, "match session [%s,%s,%d][%s %s,%s,%s]",
+	log_debug(6, "match session [%s,%s,%d][%s %s,%s,%s]:%u",
 		  rec->name, rec->conn[0].address, rec->conn[0].port,
 		  rec->iface.name, rec->iface.transport_name,
-		  rec->iface.hwaddress, rec->iface.ipaddress);
+		  rec->iface.hwaddress, rec->iface.ipaddress,
+		  rec->session.sid);
 
 	if (iface)
-		log_debug(6, "to [%s,%s,%d][%s %s,%s,%s]",
+		log_debug(6, "to [%s,%s,%d][%s %s,%s,%s]:%u",
 			  targetname, address, port, iface->name,
 			  iface->transport_name, iface->hwaddress,
-			  iface->ipaddress);
+			  iface->ipaddress, sid);
 
+	if (rec->session.sid && sid && rec->session.sid != sid)
+		return 0;
 
 	if (strlen(rec->name) && strcmp(rec->name, targetname))
 		return 0;
 
-	if (strlen(rec->conn[0].address) &&
-	    strcmp(rec->conn[0].address, address))
+	if (!iscsi_addr_match(rec->conn[0].address, address))
 		return 0;
 
 	if (rec->conn[0].port != -1 && port != rec->conn[0].port)
@@ -257,5 +335,27 @@ int iscsi_match_session(void *data, stru
 {
 	return __iscsi_match_session(data, info->targetname,
 				     info->persistent_address,
-				     info->persistent_port, &info->iface);
+				     info->persistent_port, &info->iface,
+				     info->sid);
+}
+
+int iscsi_match_session_count(void *data, struct session_info *info)
+{
+	/*
+	 * iscsi_sysfs_for_each_session expects:
+	 *   0==match -1==nomatch >0==error
+	 * but iscsi_match_session returns:
+	 *   1==match 0==nomatch
+	 */
+	if (iscsi_match_session(data, info))
+		return 0;
+	return -1;
+}
+
+int iscsi_match_target(void *data, struct session_info *info)
+{
+	return __iscsi_match_session(data, info->targetname,
+				     info->persistent_address,
+				     info->persistent_port, NULL,
+				     MATCH_ANY_SID);
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_util.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_util.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/iscsi_util.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/iscsi_util.h	2011-08-14 16:48:25.000000000 -0500
@@ -14,9 +14,14 @@ extern int increase_max_files(void);
 extern char *str_to_ipport(char *str, int *port, int *tgpt);
 
 extern int iscsi_match_session(void *data, struct session_info *info);
+extern int iscsi_match_target(void *data, struct session_info *info);
+extern int iscsi_match_session_count(void *data, struct session_info *info);
 extern int __iscsi_match_session(struct node_rec *rec, char *targetname,
 				 char *address, int port,
-				 struct iface_rec *iface);
+				 struct iface_rec *iface,
+				 unsigned sid);
+
+#define MATCH_ANY_SID 0
 
 extern char *strstrip(char *s);
 extern char *cfg_get_string_param(char *pathname, const char *key);
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/log.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/log.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/log.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/log.c	2011-08-14 16:48:25.000000000 -0500
@@ -326,6 +326,7 @@ void log_info(const char *fmt, ...)
 	va_end(ap);
 }
 
+#if 0 /* Unused */
 static void __dump_line(int level, unsigned char *buf, int *cp)
 {
 	char line[16*3+5], *lp = line;
@@ -359,6 +360,7 @@ static void __dump_char(int level, unsig
 
 #define dump_line() __dump_line(level, char_buf, &char_cnt)
 #define dump_char(ch) __dump_char(level, char_buf, &char_cnt, ch)
+#endif /* Unused */
 
 static void log_flush(void)
 {
@@ -474,6 +476,8 @@ void log_close(pid_t pid)
 		return;
 	}
 
-	kill(pid, SIGTERM);
-	waitpid(pid, &status, 0);
+	if (pid > 0) {
+		kill(pid, SIGTERM);
+		waitpid(pid, &status, 0);
+	}
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/login.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/login.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/login.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/login.c	2011-08-14 16:48:25.000000000 -0500
@@ -27,11 +27,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <poll.h>
+#include <errno.h>
 #include <sys/param.h>
 
 #include "initiator.h"
 #include "transport.h"
 #include "log.h"
+#include "iscsi_timer.h"
 
 /* caller is assumed to be well-behaved and passing NUL terminated strings */
 int
@@ -1434,11 +1437,15 @@ int
 iscsi_login_rsp(iscsi_session_t *session, iscsi_login_context_t *c)
 {
 	iscsi_conn_t *conn = &session->conn[c->cid];
+	int err;
 
 	/* read the target's response into the same buffer */
-	if (!iscsi_io_recv_pdu(conn, &c->pdu, ISCSI_DIGEST_NONE, c->data,
-			    c->max_data_length, ISCSI_DIGEST_NONE,
-			    c->timeout)) {
+	err = iscsi_io_recv_pdu(conn, &c->pdu, ISCSI_DIGEST_NONE, c->data,
+			        c->max_data_length, ISCSI_DIGEST_NONE,
+			        c->timeout);
+	if (err == -EAGAIN) {
+		goto done;
+	} else if (err < 0) {
 		/*
 		 * FIXME: caller might want us to distinguish I/O
 		 * error and timeout. Might want to switch portals on
@@ -1449,6 +1456,7 @@ iscsi_login_rsp(iscsi_session_t *session
 		goto done;
 	}
 
+	err = -EIO;
 	c->received_pdu = 1;
 
 	/* check the PDU response type */
@@ -1490,7 +1498,7 @@ iscsi_login_rsp(iscsi_session_t *session
 		if (c->ret == LOGIN_OK)
 			c->ret = LOGIN_FAILED;
 	}
-	return 1;
+	return err;
 }
 
 /**
@@ -1514,7 +1522,9 @@ iscsi_login(iscsi_session_t *session, in
 {
 	iscsi_conn_t *conn = &session->conn[cid];
 	iscsi_login_context_t *c = &conn->login_context;
-	int ret;
+	struct timeval connection_timer;
+	struct pollfd pfd;
+	int ret, timeout;
 
 	/*
 	 * assume iscsi_login is only called from discovery, so it is
@@ -1532,15 +1542,63 @@ iscsi_login(iscsi_session_t *session, in
 	do {
 		if (iscsi_login_req(session, c))
 			return c->ret;
-		ret = iscsi_login_rsp(session, c);
 
-		if (status_class)
-			*status_class = c->status_class;
-		if (status_detail)
-			*status_detail = c->status_detail;
+		/*
+		 * TODO: merge the poll and req/rsp code with the discovery
+		 * poll and text req/rsp.
+		 */
+		iscsi_timer_set(&connection_timer,
+				session->conn[0].active_timeout);
+		timeout = iscsi_timer_msecs_until(&connection_timer);
+
+		memset(&pfd, 0, sizeof (pfd));
+		pfd.fd = conn->socket_fd;
+		pfd.events = POLLIN | POLLPRI;
+
+repoll:
+		pfd.revents = 0;
+		ret = poll(&pfd, 1, timeout);
+		log_debug(7, "%s: Poll return %d\n", __FUNCTION__, ret);
+		if (iscsi_timer_expired(&connection_timer)) {
+			log_warning("Login response timeout. Waited %d "
+				    "seconds and did not get reponse PDU.\n",
+				    session->conn[0].active_timeout);
+			c->ret = LOGIN_FAILED;
+			return c->ret;
+		}
+
+		if (ret > 0) {
+			if (pfd.revents & (POLLIN | POLLPRI)) {
+				ret = iscsi_login_rsp(session, c);
+				if (ret ==  -EAGAIN)
+					goto repoll;
+
+				if (status_class)
+					*status_class = c->status_class;
+				if (status_detail)
+					*status_detail = c->status_detail;
+
+				if (ret)
+					return c->ret;
+			} else if (pfd.revents & POLLHUP) {
+				log_warning("Login POLLHUP");
+				c->ret = LOGIN_FAILED;
+				return c->ret;
+			} else if (pfd.revents & POLLNVAL) {
+				log_warning("Login POLLNVAL");
+				c->ret = LOGIN_IO_ERROR;
+				return c->ret;
+			} else if (pfd.revents & POLLERR) {
+				log_warning("Login POLLERR");
+				c->ret = LOGIN_IO_ERROR;
+				return c->ret;
+			}
 
-		if (ret)
+		} else if (ret < 0) {
+			log_error("Login poll error.\n");
+			c->ret = LOGIN_FAILED;
 			return c->ret;
+		}
 	} while (conn->current_stage != ISCSI_FULL_FEATURE_PHASE);
 
 	c->ret = LOGIN_OK;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/Makefile open-iscsi-2.0-872-rc4-bnx2i.sync/usr/Makefile
--- open-iscsi-2.0-872-rc4-bnx2i/usr/Makefile	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/Makefile	2011-08-14 16:48:25.000000000 -0500
@@ -21,10 +21,12 @@ ifeq ($(OSNAME),Linux)
 	endif
 	endif
 IPC_OBJ=netlink.o
+DCB_OBJ=dcb_app.o
 else
 ifeq ($(OSNAME),FreeBSD)
 IPC_CFLAGS=
 IPC_OBJ=ioctl.o
+DCB_OBJ=
 endif
 endif
 
@@ -37,12 +39,13 @@ PROGRAMS = iscsid iscsiadm iscsistart
 # libc compat files
 SYSDEPS_SRCS = $(wildcard ../utils/sysdeps/*.o)
 # sources shared between iscsid, iscsiadm and iscsistart
-ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o login.o log.o md5.o sha1.o iface.o \
-	idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o iscsi_net_util.o \
-	iscsid_req.o $(SYSDEPS_SRCS)
+ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o md5.o \
+	sha1.o iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
+	iscsi_net_util.o iscsid_req.o transport.o cxgbi.o be2iscsi.o \
+	initiator_common.o iscsi_err.o $(IPC_OBJ)  $(SYSDEPS_SRCS) $(DCB_OBJ)
 # core initiator files
-INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o \
-		transport.o cxgb3i.o be2iscsi.o
+INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o
+
 # fw boot files
 FW_BOOT_SRCS = $(wildcard ../utils/fwparam_ibft/*.o)
 
@@ -51,14 +54,14 @@ DISCOVERY_SRCS = $(FW_BOOT_SRCS) strings
 
 all: $(PROGRAMS)
 
-iscsid: $(ISCSI_LIB_SRCS) $(IPC_OBJ) $(INITIATOR_SRCS) $(DISCOVERY_SRCS) \
+iscsid: $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(DISCOVERY_SRCS) \
 	iscsid.o session_mgmt.o discoveryd.o
-	$(CC) $(CFLAGS) $^ -o $@ -L../utils/open-isns -lisns -lcrypto
+	$(CC) $(CFLAGS) $^ -o $@ -L../utils/open-isns -lisns
 
 iscsiadm: $(ISCSI_LIB_SRCS) $(DISCOVERY_SRCS) iscsiadm.o session_mgmt.o
-	$(CC) $(CFLAGS) $^ -o $@ -L../utils/open-isns -lisns -lcrypto
+	$(CC) $(CFLAGS) $^ -o $@ -L../utils/open-isns -lisns
 
-iscsistart: $(IPC_OBJ) $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(FW_BOOT_SRCS) \
+iscsistart: $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(FW_BOOT_SRCS) \
 		iscsistart.o statics.o
 	$(CC) $(CFLAGS) -static $^ -o $@
 clean:
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/mgmt_ipc.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/mgmt_ipc.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/mgmt_ipc.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/mgmt_ipc.c	2011-08-14 16:48:25.000000000 -0500
@@ -35,6 +35,7 @@
 #include "transport.h"
 #include "sysdeps.h"
 #include "iscsi_ipc.h"
+#include "iscsi_err.h"
 
 #define PEERUSER_MAX	64
 #define EXTMSG_MAX	(64 * 1024)
@@ -79,13 +80,13 @@ mgmt_ipc_close(int fd)
 		close(fd);
 }
 
-static mgmt_ipc_err_e
+static int 
 mgmt_ipc_session_login(queue_task_t *qtask)
 {
 	return session_login_task(&qtask->req.u.session.rec, qtask);
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_session_getstats(queue_task_t *qtask)
 {
 	int sid = qtask->req.u.session.sid;
@@ -93,7 +94,7 @@ mgmt_ipc_session_getstats(queue_task_t *
 	int rc;
 
 	if (!(session = session_find_by_sid(sid)))
-		return MGMT_IPC_ERR_NOT_FOUND;
+		return ISCSI_ERR_SESS_NOT_FOUND;
 
 	rc = ipc->get_stats(session->t->handle,
 		session->id, session->conn[0].id,
@@ -102,33 +103,33 @@ mgmt_ipc_session_getstats(queue_task_t *
 	if (rc) {
 		log_error("get_stats(): IPC error %d "
 			"session [%02d]", rc, sid);
-		return MGMT_IPC_ERR_INTERNAL;
+		return ISCSI_ERR_INTERNAL;
 	}
 
-	mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK);
-	return MGMT_IPC_OK;
+	mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_send_targets(queue_task_t *qtask)
 {
 	iscsiadm_req_t *req = &qtask->req;
-	mgmt_ipc_err_e err;
+	int err;
 
 	err = iscsi_host_send_targets(qtask, req->u.st.host_no,
 					  req->u.st.do_login,
 					  &req->u.st.ss);
 	mgmt_ipc_write_rsp(qtask, err);
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_session_logout(queue_task_t *qtask)
 {
 	return session_logout_task(qtask->req.u.session.sid, qtask);
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_session_sync(queue_task_t *qtask)
 {
 	struct ipc_msg_session *session= &qtask->req.u.session;
@@ -136,16 +137,16 @@ mgmt_ipc_session_sync(queue_task_t *qtas
 	return iscsi_sync_session(&session->rec, qtask, session->sid);
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_cfg_initiatorname(queue_task_t *qtask)
 {
 	if (dconfig->initiator_name)
 		strcpy(qtask->rsp.u.config.var, dconfig->initiator_name);
-	mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK);
-	return MGMT_IPC_OK;
+	mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_session_info(queue_task_t *qtask)
 {
 	int sid = qtask->req.u.session.sid;
@@ -154,61 +155,50 @@ mgmt_ipc_session_info(queue_task_t *qtas
 
 	if (!(session = session_find_by_sid(sid))) {
 		log_debug(1, "session with sid %d not found!", sid);
-		return MGMT_IPC_ERR_NOT_FOUND;
+		return ISCSI_ERR_SESS_NOT_FOUND;
 	}
 
 	info = &qtask->rsp.u.session_state;
 	info->conn_state = session->conn[0].state;
 	info->session_state = session->r_stage;
 
-	mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK);
-	return MGMT_IPC_OK;
+	mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_cfg_initiatoralias(queue_task_t *qtask)
 {
 	strcpy(qtask->rsp.u.config.var, dconfig->initiator_alias);
-	mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK);
-	return MGMT_IPC_OK;
+	mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_cfg_filename(queue_task_t *qtask)
 {
 	strcpy(qtask->rsp.u.config.var, dconfig->config_file);
-	mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK);
-	return MGMT_IPC_OK;
+	mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_conn_add(queue_task_t *qtask)
 {
-	return MGMT_IPC_ERR;
+	return ISCSI_ERR;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_immediate_stop(queue_task_t *qtask)
 {
 	event_loop_exit(qtask);
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_conn_remove(queue_task_t *qtask)
 {
-	return MGMT_IPC_ERR;
-}
-
-static mgmt_ipc_err_e
-mgmt_ipc_host_set_param(queue_task_t *qtask)
-{
-	struct ipc_msg_set_host_param *hp = &qtask->req.u.set_host_param;
-	int err;
-
-	err = iscsi_host_set_param(hp->host_no, hp->param, hp->value);
-	mgmt_ipc_write_rsp(qtask, err);
-	return MGMT_IPC_OK;
+	return ISCSI_ERR;
 }
 
 /*
@@ -263,12 +253,11 @@ again:
 	return argc;
 }
 
-static mgmt_ipc_err_e
-mgmt_ipc_notify_common(queue_task_t *qtask,
-		mgmt_ipc_err_e (*handler)(int, char **))
+static int
+mgmt_ipc_notify_common(queue_task_t *qtask, int (*handler)(int, char **))
 {
 	char	**argv = NULL;
-	int	argc, err = MGMT_IPC_ERR;
+	int	argc, err = ISCSI_ERR;
 
 	argc = mgmt_ipc_parse_strings(qtask, &argv);
 	if (argc > 0)
@@ -277,54 +266,54 @@ mgmt_ipc_notify_common(queue_task_t *qta
 	if (argv)
 		free(argv);
 	mgmt_ipc_write_rsp(qtask, err);
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
 /* Replace these dummies as you implement them
    elsewhere */
-static mgmt_ipc_err_e
+static int
 iscsi_discovery_add_node(int argc, char **argv)
 {
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 iscsi_discovery_del_node(int argc, char **argv)
 {
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 iscsi_discovery_add_portal(int argc, char **argv)
 {
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 iscsi_discovery_del_portal(int argc, char **argv)
 {
-	return MGMT_IPC_OK;
+	return ISCSI_SUCCESS;
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_notify_add_node(queue_task_t *qtask)
 {
 	return mgmt_ipc_notify_common(qtask, iscsi_discovery_add_node);
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_notify_del_node(queue_task_t *qtask)
 {
 	return mgmt_ipc_notify_common(qtask, iscsi_discovery_del_node);
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_notify_add_portal(queue_task_t *qtask)
 {
 	return mgmt_ipc_notify_common(qtask, iscsi_discovery_add_portal);
 }
 
-static mgmt_ipc_err_e
+static int
 mgmt_ipc_notify_del_portal(queue_task_t *qtask)
 {
 	return mgmt_ipc_notify_common(qtask, iscsi_discovery_del_portal);
@@ -433,7 +422,7 @@ mgmt_ipc_destroy_queue_task(queue_task_t
  * is for.
  */
 void
-mgmt_ipc_write_rsp(queue_task_t *qtask, mgmt_ipc_err_e err)
+mgmt_ipc_write_rsp(queue_task_t *qtask, int err)
 {
 	if (!qtask)
 		return;
@@ -446,7 +435,8 @@ mgmt_ipc_write_rsp(queue_task_t *qtask, 
 	}
 
 	qtask->rsp.err = err;
-	write(qtask->mgmt_ipc_fd, &qtask->rsp, sizeof(qtask->rsp));
+	if (write(qtask->mgmt_ipc_fd, &qtask->rsp, sizeof(qtask->rsp)) < 0)
+		log_error("IPC qtask write failed: %s", strerror(errno));
 	close(qtask->mgmt_ipc_fd);
 	mgmt_ipc_destroy_queue_task(qtask);
 }
@@ -510,7 +500,6 @@ static mgmt_ipc_fn_t *	mgmt_ipc_function
 [MGMT_IPC_CONFIG_IALIAS]	= mgmt_ipc_cfg_initiatoralias,
 [MGMT_IPC_CONFIG_FILE]		= mgmt_ipc_cfg_filename,
 [MGMT_IPC_IMMEDIATE_STOP]	= mgmt_ipc_immediate_stop,
-[MGMT_IPC_SET_HOST_PARAM]	= mgmt_ipc_host_set_param,
 [MGMT_IPC_NOTIFY_ADD_NODE]	= mgmt_ipc_notify_add_node,
 [MGMT_IPC_NOTIFY_DEL_NODE]	= mgmt_ipc_notify_del_node,
 [MGMT_IPC_NOTIFY_ADD_PORTAL]	= mgmt_ipc_notify_add_portal,
@@ -538,7 +527,7 @@ void mgmt_ipc_handle(int accept_fd)
 	qtask->mgmt_ipc_fd = fd;
 
 	if (!mgmt_peeruser(fd, user) || strncmp(user, "root", PEERUSER_MAX)) {
-		err = MGMT_IPC_ERR_ACCESS;
+		err = ISCSI_ERR_ACCESS;
 		goto err;
 	}
 
@@ -556,12 +545,12 @@ void mgmt_ipc_handle(int accept_fd)
 		/* If the handler returns OK, this means it
 		 * already sent the reply. */
 		err = handler(qtask);
-		if (err == MGMT_IPC_OK)
+		if (err == ISCSI_SUCCESS)
 			return;
 	} else {
 		log_error("unknown request: %s(%d) %u",
 			  __FUNCTION__, __LINE__, command);
-		err = MGMT_IPC_ERR_INVALID_REQ;
+		err = ISCSI_ERR_INVALID_MGMT_REQ;
 	}
 
 err:
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/mgmt_ipc.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/mgmt_ipc.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/mgmt_ipc.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/mgmt_ipc.h	2011-08-14 16:48:25.000000000 -0500
@@ -26,30 +26,6 @@
 #define ISCSIADM_NAMESPACE	"ISCSIADM_ABSTRACT_NAMESPACE"
 #define PEERUSER_MAX		64
 
-typedef enum mgmt_ipc_err {
-	MGMT_IPC_OK			= 0,
-	MGMT_IPC_ERR			= 1,
-	MGMT_IPC_ERR_NOT_FOUND		= 2,
-	MGMT_IPC_ERR_NOMEM		= 3,
-	MGMT_IPC_ERR_TRANS_FAILURE	= 4,
-	MGMT_IPC_ERR_LOGIN_FAILURE	= 5,
-	MGMT_IPC_ERR_IDBM_FAILURE	= 6,
-	MGMT_IPC_ERR_INVAL		= 7,
-	MGMT_IPC_ERR_TRANS_TIMEOUT	= 8,
-	MGMT_IPC_ERR_INTERNAL		= 9,
-	MGMT_IPC_ERR_LOGOUT_FAILURE	= 10,
-	MGMT_IPC_ERR_PDU_TIMEOUT	= 11,
-	MGMT_IPC_ERR_TRANS_NOT_FOUND	= 12,
-	MGMT_IPC_ERR_ACCESS		= 13,
-	MGMT_IPC_ERR_TRANS_CAPS		= 14,
-	MGMT_IPC_ERR_EXISTS		= 15,
-	MGMT_IPC_ERR_INVALID_REQ	= 16,
-	MGMT_IPC_ERR_ISNS_UNAVAILABLE	= 17,
-	MGMT_IPC_ERR_ISCSID_COMM_ERR	= 18,
-	MGMT_IPC_ERR_FATAL_LOGIN_FAILURE = 19,
-	MGMT_IPC_ERR_ISCSID_NOTCONN	= 20,
-} mgmt_ipc_err_e;
-
 typedef enum iscsiadm_cmd {
 	MGMT_IPC_UNKNOWN		= 0,
 	MGMT_IPC_SESSION_LOGIN		= 1,
@@ -66,11 +42,10 @@ typedef enum iscsiadm_cmd {
 	MGMT_IPC_SESSION_INFO		= 13,
 	MGMT_IPC_ISNS_DEV_ATTR_QUERY	= 14,
 	MGMT_IPC_SEND_TARGETS		= 15,
-	MGMT_IPC_SET_HOST_PARAM		= 16,
-	MGMT_IPC_NOTIFY_ADD_NODE	= 17,
-	MGMT_IPC_NOTIFY_DEL_NODE	= 18,
-	MGMT_IPC_NOTIFY_ADD_PORTAL	= 19,
-	MGMT_IPC_NOTIFY_DEL_PORTAL	= 20,
+	MGMT_IPC_NOTIFY_ADD_NODE	= 16,
+	MGMT_IPC_NOTIFY_DEL_NODE	= 17,
+	MGMT_IPC_NOTIFY_ADD_PORTAL	= 18,
+	MGMT_IPC_NOTIFY_DEL_PORTAL	= 19,
 
 	__MGMT_IPC_MAX_COMMAND
 } iscsiadm_cmd_e;
@@ -108,7 +83,7 @@ typedef struct iscsiadm_req {
 /* IPC Response */
 typedef struct iscsiadm_rsp {
 	iscsiadm_cmd_e command;
-	mgmt_ipc_err_e err;
+	int err;	/* ISCSI_ERR value */
 
 	union {
 #define MGMT_IPC_GETSTATS_BUF_MAX	(sizeof(struct iscsi_uevent) + \
@@ -132,10 +107,10 @@ typedef struct iscsiadm_rsp {
 } iscsiadm_rsp_t;
 
 struct queue_task;
-typedef mgmt_ipc_err_e	mgmt_ipc_fn_t(struct queue_task *);
+typedef int mgmt_ipc_fn_t(struct queue_task *);
 
 struct queue_task;
-void mgmt_ipc_write_rsp(struct queue_task *qtask, mgmt_ipc_err_e err);
+void mgmt_ipc_write_rsp(struct queue_task *qtask, int err);
 int mgmt_ipc_listen(void);
 void mgmt_ipc_close(int fd);
 void mgmt_ipc_handle(int accept_fd);
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/netlink.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/netlink.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/netlink.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/netlink.c	2011-08-14 16:48:25.000000000 -0500
@@ -33,7 +33,6 @@
 
 #include "types.h"
 #include "iscsi_if.h"
-#include "iscsid.h"
 #include "log.h"
 #include "iscsi_ipc.h"
 #include "initiator.h"
@@ -50,23 +49,25 @@ static void *nlm_sendbuf;
 static void *nlm_recvbuf;
 static void *pdu_sendbuf;
 static void *setparam_buf;
+static struct iscsi_ipc_ev_clbk *ipc_ev_clbk;
 
 static int ctldev_handle(void);
 
-#define NLM_BUF_DEFAULT_MAX \
-	(NLMSG_SPACE(ISCSI_DEF_MAX_RECV_SEG_LEN + \
-			 sizeof(struct iscsi_hdr)))
+#define NLM_BUF_DEFAULT_MAX (NLMSG_SPACE(ISCSI_DEF_MAX_RECV_SEG_LEN +	\
+					sizeof(struct iscsi_uevent) +	\
+					sizeof(struct iscsi_hdr)))
+
+#define PDU_SENDBUF_DEFAULT_MAX	(ISCSI_DEF_MAX_RECV_SEG_LEN +		\
+					sizeof(struct iscsi_uevent) +	\
+					sizeof(struct iscsi_hdr))
 
-#define PDU_SENDBUF_DEFAULT_MAX \
-	(ISCSI_DEF_MAX_RECV_SEG_LEN + sizeof(struct iscsi_hdr))
-
-#define NLM_SETPARAM_DEFAULT_MAX \
-	(NI_MAXHOST + 1 + sizeof(struct iscsi_uevent))
+#define NLM_SETPARAM_DEFAULT_MAX (NI_MAXHOST + 1 + sizeof(struct iscsi_uevent))
 
 static int
 kread(char *data, int count)
 {
-	log_debug(7, "in %s", __FUNCTION__);
+	log_debug(7, "in %s %u %u %p %p", __FUNCTION__, recvlen, count,
+		  data, recvbuf);
 
 	memcpy(data, recvbuf + recvlen, count);
 	recvlen += count;
@@ -107,6 +108,12 @@ nlpayload_read(int ctrl_fd, char *data, 
 
 	iov.iov_base = nlm_recvbuf;
 	iov.iov_len = NLMSG_SPACE(count);
+
+	if (iov.iov_len > NLM_BUF_DEFAULT_MAX) {
+		log_error("Cannot read %lu bytes. nlm_recvbuf too small.",
+			  iov.iov_len);
+		return -1;
+	}
 	memset(iov.iov_base, 0, iov.iov_len);
 
 	memset(&msg, 0, sizeof(msg));
@@ -142,7 +149,8 @@ nlpayload_read(int ctrl_fd, char *data, 
 	 */
 	rc = recvmsg(ctrl_fd, &msg, flags);
 
-	memcpy(data, NLMSG_DATA(iov.iov_base), count);
+	if (data)
+		memcpy(data, NLMSG_DATA(iov.iov_base), count);
 
 	return rc;
 }
@@ -153,7 +161,6 @@ kwritev(enum iscsi_uevent_e type, struct
 	int i, rc;
 	struct nlmsghdr *nlh;
 	struct msghdr msg;
-	struct iovec iov;
 	int datalen = 0;
 
 	log_debug(7, "in %s", __FUNCTION__);
@@ -172,27 +179,25 @@ kwritev(enum iscsi_uevent_e type, struct
 	}
 
 	nlh = nlm_sendbuf;
-	memset(nlh, 0, NLMSG_SPACE(datalen));
+	memset(nlh, 0, NLMSG_SPACE(0));
 
-	nlh->nlmsg_len = NLMSG_SPACE(datalen);
+	datalen = 0;
+	for (i = 1; i < count; i++)
+		datalen += iovp[i].iov_len;
+
+	nlh->nlmsg_len = NLMSG_ALIGN(datalen);
 	nlh->nlmsg_pid = getpid();
 	nlh->nlmsg_flags = 0;
 	nlh->nlmsg_type = type;
 
-	datalen = 0;
-	for (i = 0; i < count; i++) {
-		memcpy(NLMSG_DATA(nlh) + datalen, iovp[i].iov_base,
-		       iovp[i].iov_len);
-		datalen += iovp[i].iov_len;
-	}
-	iov.iov_base = (void*)nlh;
-	iov.iov_len = nlh->nlmsg_len;
+	iovp[0].iov_base = (void *)nlh;
+	iovp[0].iov_len = sizeof(*nlh);
 
 	memset(&msg, 0, sizeof(msg));
 	msg.msg_name= (void*)&dest_addr;
 	msg.msg_namelen = sizeof(dest_addr);
-	msg.msg_iov = &iov;
-	msg.msg_iovlen = 1;
+	msg.msg_iov = iovp;
+	msg.msg_iovlen = count;
 
 	do {
 		/*
@@ -253,19 +258,15 @@ kwritev(enum iscsi_uevent_e type, struct
  *        cleanup. (Dima)
  */
 static int
-__kipc_call(void *iov_base, int iov_len)
+__kipc_call(struct iovec *iovp, int count)
 {
 	int rc, iferr;
-	struct iovec iov;
-	struct iscsi_uevent *ev = iov_base;
+	struct iscsi_uevent *ev = iovp[1].iov_base;
 	enum iscsi_uevent_e type = ev->type;
 
 	log_debug(7, "in %s", __FUNCTION__);
 
-	iov.iov_base = iov_base;
-	iov.iov_len = iov_len;
-
-	rc = kwritev(type, &iov, 1);
+	rc = kwritev(type, iovp, count);
 
 	do {
 		if ((rc = nlpayload_read(ctrl_fd, (void*)ev,
@@ -325,6 +326,7 @@ ksendtargets(uint64_t transport_handle, 
 {
 	int rc, addrlen;
 	struct iscsi_uevent *ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -346,7 +348,9 @@ ksendtargets(uint64_t transport_handle, 
 	}
 	memcpy(setparam_buf + sizeof(*ev), addr, addrlen);
 
-	rc = __kipc_call(ev, sizeof(*ev) + addrlen);
+	iov[1].iov_base = ev;
+	iov[1].iov_len = sizeof(*ev) + addrlen;
+	rc = __kipc_call(iov, 2);
 	if (rc < 0) {
 		log_error("sendtargets failed rc%d\n", rc);
 		return rc;
@@ -361,6 +365,7 @@ kcreate_session(uint64_t transport_handl
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -381,9 +386,11 @@ kcreate_session(uint64_t transport_handl
 		ev.u.c_bound_session.ep_handle = ep_handle;
 	}
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	*hostno = ev.r.c_session_ret.host_no;
 	*out_sid = ev.r.c_session_ret.sid;
@@ -396,6 +403,7 @@ kdestroy_session(uint64_t transport_hand
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -405,9 +413,11 @@ kdestroy_session(uint64_t transport_hand
 	ev.transport_handle = transport_handle;
 	ev.u.d_session.sid = sid;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	return 0;
 }
@@ -417,6 +427,7 @@ kunbind_session(uint64_t transport_handl
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -426,9 +437,11 @@ kunbind_session(uint64_t transport_handl
 	ev.transport_handle = transport_handle;
 	ev.u.d_session.sid = sid;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	return 0;
 }
@@ -439,6 +452,7 @@ kcreate_conn(uint64_t transport_handle, 
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -449,7 +463,10 @@ kcreate_conn(uint64_t transport_handle, 
 	ev.u.c_conn.cid = cid;
 	ev.u.c_conn.sid = sid;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0) {
 		log_debug(7, "returned %d", rc);
 		return rc;
 	}
@@ -466,6 +483,7 @@ kdestroy_conn(uint64_t transport_handle,
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -476,9 +494,11 @@ kdestroy_conn(uint64_t transport_handle,
 	ev.u.d_conn.sid = sid;
 	ev.u.d_conn.cid = cid;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	return 0;
 }
@@ -489,6 +509,7 @@ kbind_conn(uint64_t transport_handle, ui
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -501,9 +522,11 @@ kbind_conn(uint64_t transport_handle, ui
 	ev.u.b_conn.transport_eph = transport_eph;
 	ev.u.b_conn.is_leading = is_leading;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	*retcode = ev.r.retcode;
 
@@ -515,6 +538,7 @@ ksend_pdu_begin(uint64_t transport_handl
 			int hdr_size, int data_size)
 {
 	struct iscsi_uevent *ev;
+	int total_xmitlen = sizeof(*ev) + hdr_size + data_size;
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -523,8 +547,13 @@ ksend_pdu_begin(uint64_t transport_handl
 		exit(-EIO);
 	}
 
+	if (total_xmitlen > PDU_SENDBUF_DEFAULT_MAX) {
+		log_error("BUG: Cannot send %d bytes.", total_xmitlen);
+		exit(-EINVAL);
+	}
+
 	xmitbuf = pdu_sendbuf;
-	memset(xmitbuf, 0, sizeof(*ev) + hdr_size + data_size);
+	memset(xmitbuf, 0, total_xmitlen);
 	xmitlen = sizeof(*ev);
 	ev = xmitbuf;
 	memset(ev, 0, sizeof(*ev));
@@ -545,7 +574,7 @@ ksend_pdu_end(uint64_t transport_handle,
 {
 	int rc;
 	struct iscsi_uevent *ev;
-	struct iovec iov;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -559,10 +588,11 @@ ksend_pdu_end(uint64_t transport_handle,
 		exit(-EIO);
 	}
 
-	iov.iov_base = xmitbuf;
-	iov.iov_len = xmitlen;
+	iov[1].iov_base = xmitbuf;
+	iov[1].iov_len = xmitlen;
 
-	if ((rc = __kipc_call(xmitbuf, xmitlen)) < 0)
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		goto err;
 	if (ev->r.retcode) {
 		*retcode = ev->r.retcode;
@@ -592,6 +622,7 @@ kset_host_param(uint64_t transport_handl
 	struct iscsi_uevent *ev;
 	char *param_str;
 	int rc, len;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -618,9 +649,11 @@ kset_host_param(uint64_t transport_handl
 	}
 	ev->u.set_host_param.len = len = strlen(param_str) + 1;
 
-	if ((rc = __kipc_call(ev, sizeof(*ev) + len)) < 0) {
+	iov[1].iov_base = ev;
+	iov[1].iov_len = sizeof(*ev) + len;
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	return 0;
 }
@@ -632,6 +665,7 @@ kset_param(uint64_t transport_handle, ui
 	struct iscsi_uevent *ev;
 	char *param_str;
 	int rc, len;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -659,9 +693,11 @@ kset_param(uint64_t transport_handle, ui
 	}
 	ev->u.set_param.len = len = strlen(param_str) + 1;
 
-	if ((rc = __kipc_call(ev, sizeof(*ev) + len)) < 0) {
+	iov[1].iov_base = ev;
+	iov[1].iov_len = sizeof(*ev) + len;
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	return 0;
 }
@@ -671,6 +707,7 @@ kstop_conn(uint64_t transport_handle, ui
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -682,9 +719,11 @@ kstop_conn(uint64_t transport_handle, ui
 	ev.u.stop_conn.cid = cid;
 	ev.u.stop_conn.flag = flag;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	return 0;
 }
@@ -695,6 +734,7 @@ kstart_conn(uint64_t transport_handle, u
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -705,9 +745,11 @@ kstart_conn(uint64_t transport_handle, u
 	ev.u.start_conn.sid = sid;
 	ev.u.start_conn.cid = cid;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	*retcode = ev.r.retcode;
 	return 0;
@@ -716,18 +758,34 @@ kstart_conn(uint64_t transport_handle, u
 static int
 krecv_pdu_begin(struct iscsi_conn *conn)
 {
+	int rc;
+
 	log_debug(7, "in %s", __FUNCTION__);
 
 	if (recvbuf) {
 		log_error("recv's begin state machine bug?");
 		return -EIO;
 	}
+
+	if (!conn->recv_context) {
+		rc = ipc->ctldev_handle();
+		if (rc == -ENXIO)
+			/* event for some other conn */
+			return -EAGAIN;
+		else if (rc < 0)
+			/* fatal handling error or conn error */
+			return rc;
+		/*
+		 * Session create/destroy event for another conn
+		 */
+		if (!conn->recv_context)
+			return -EAGAIN;
+	}
+
 	recvbuf = conn->recv_context->data + sizeof(struct iscsi_uevent);
 	recvlen = 0;
 
-	log_debug(3, "recv PDU began, pdu handle 0x%p",
-		  recvbuf);
-
+	log_debug(3, "recv PDU began, pdu handle %p", recvbuf);
 	return 0;
 }
 
@@ -744,7 +802,7 @@ krecv_pdu_end(struct iscsi_conn *conn)
 	log_debug(3, "recv PDU finished for pdu handle 0x%p",
 		  recvbuf);
 
-	iscsi_conn_context_put(conn->recv_context);
+	ipc_ev_clbk->put_ev_context(conn->recv_context);
 	conn->recv_context = NULL;
 	recvbuf = NULL;
 	return 0;
@@ -756,6 +814,7 @@ ktransport_ep_connect(iscsi_conn_t *conn
 	int rc, addrlen;
 	struct iscsi_uevent *ev;
 	struct sockaddr *dst_addr = (struct sockaddr *)&conn->saddr;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -783,7 +842,10 @@ ktransport_ep_connect(iscsi_conn_t *conn
 	}
 	memcpy(setparam_buf + sizeof(*ev), dst_addr, addrlen);
 
-	if ((rc = __kipc_call(ev, sizeof(*ev) + addrlen)) < 0)
+	iov[1].iov_base = ev;
+	iov[1].iov_len = sizeof(*ev) + addrlen;
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
 
 	if (!ev->r.ep_connect_ret.handle)
@@ -801,6 +863,7 @@ ktransport_ep_poll(iscsi_conn_t *conn, i
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -811,7 +874,10 @@ ktransport_ep_poll(iscsi_conn_t *conn, i
 	ev.u.ep_poll.ep_handle  = conn->transport_ep_handle;
 	ev.u.ep_poll.timeout_ms = timeout_ms;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0)
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
 
 	return ev.r.retcode;
@@ -822,6 +888,7 @@ ktransport_ep_disconnect(iscsi_conn_t *c
 {
 	int rc;
 	struct iscsi_uevent ev;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -834,7 +901,10 @@ ktransport_ep_disconnect(iscsi_conn_t *c
 	ev.transport_handle = conn->session->t->handle;
 	ev.u.ep_disconnect.ep_handle = conn->transport_ep_handle;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0) {
 		log_error("connnection %d:%d transport disconnect failed for "
 			  "ep %" PRIu64 " with error %d.", conn->session->id,
 			  conn->id, conn->transport_ep_handle, rc);
@@ -851,6 +921,7 @@ kget_stats(uint64_t transport_handle, ui
 	struct iscsi_uevent ev;
 	char nlm_ev[NLMSG_SPACE(sizeof(struct iscsi_uevent))];
 	struct nlmsghdr *nlh;
+	struct iovec iov[2];
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -861,9 +932,11 @@ kget_stats(uint64_t transport_handle, ui
 	ev.u.get_stats.sid = sid;
 	ev.u.get_stats.cid = cid;
 
-	if ((rc = __kipc_call(&ev, sizeof(ev))) < 0) {
+	iov[1].iov_base = &ev;
+	iov[1].iov_len = sizeof(ev);
+	rc = __kipc_call(iov, 2);
+	if (rc < 0)
 		return rc;
-	}
 
 	if ((rc = nl_read(ctrl_fd, nlm_ev,
 		NLMSG_SPACE(sizeof(struct iscsi_uevent)), MSG_PEEK)) < 0) {
@@ -889,12 +962,60 @@ kget_stats(uint64_t transport_handle, ui
 	return 0;
 }
 
+static int
+kset_net_config(uint64_t transport_handle, uint32_t host_no,
+		struct iovec *iovs, uint32_t param_count)
+{
+	struct iscsi_uevent ev;
+	int rc, ev_len;
+	struct iovec *iov = iovs + 1;
+
+	log_debug(8, "in %s", __FUNCTION__);
+
+	ev_len = sizeof(ev);
+	ev.type = ISCSI_UEVENT_SET_IFACE_PARAMS;
+	ev.transport_handle = transport_handle;
+	ev.u.set_iface_params.host_no = host_no;
+	/* first two iovs for nlmsg hdr and ev */
+	ev.u.set_iface_params.count = param_count - 2;
+
+	iov->iov_base = &ev;
+	iov->iov_len = ev_len;
+	rc = __kipc_call(iovs, param_count);
+	if (rc < 0)
+		return rc;
+
+	return 0;
+}
+
+static int krecv_conn_state(struct iscsi_conn *conn, int *state)
+{
+	int rc;
+
+	rc = ipc->ctldev_handle();
+	if (rc == -ENXIO) {
+		/* event for some other conn */
+		rc = -EAGAIN;
+		goto exit;
+	} else if (rc < 0)
+		/* fatal handling error or conn error */
+		goto exit;
+
+	*state = *(enum iscsi_conn_state *)conn->recv_context->data;
+
+	ipc_ev_clbk->put_ev_context(conn->recv_context);
+	conn->recv_context = NULL;
+
+exit:
+	return rc;
+}
+
 static void drop_data(struct nlmsghdr *nlh)
 {
 	int ev_size;
 
 	ev_size = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct nlmsghdr));
-	nlpayload_read(ctrl_fd, setparam_buf, ev_size, 0);
+	nlpayload_read(ctrl_fd, NULL, ev_size, 0);
 }
 
 static int ctldev_handle(void)
@@ -905,8 +1026,8 @@ static int ctldev_handle(void)
 	iscsi_conn_t *conn = NULL;
 	char nlm_ev[NLMSG_SPACE(sizeof(struct iscsi_uevent))];
 	struct nlmsghdr *nlh;
-	struct iscsi_conn_context *conn_context;
-	uint32_t sid = 0, cid = 0;
+	struct iscsi_ev_context *ev_context;
+	uint32_t sid = 0, cid = 0, state = 0;
 
 	log_debug(7, "in %s", __FUNCTION__);
 
@@ -925,13 +1046,15 @@ static int ctldev_handle(void)
 	/* old kernels sent ISCSI_UEVENT_CREATE_SESSION on creation */
 	case ISCSI_UEVENT_CREATE_SESSION:
 		drop_data(nlh);
-		iscsi_async_session_creation(ev->r.c_session_ret.host_no,
-					     ev->r.c_session_ret.sid);
+		if (ipc_ev_clbk->create_session)
+			ipc_ev_clbk->create_session(ev->r.c_session_ret.host_no,
+						    ev->r.c_session_ret.sid);
 		return 0;
 	case ISCSI_KEVENT_DESTROY_SESSION:
 		drop_data(nlh);
-		iscsi_async_session_destruction(ev->r.d_session.host_no,
-						ev->r.d_session.sid);
+		if (ipc_ev_clbk->destroy_session)
+			ipc_ev_clbk->destroy_session(ev->r.d_session.host_no,
+						     ev->r.d_session.sid);
 		return 0;
 	case ISCSI_KEVENT_RECV_PDU:
 		sid = ev->r.recv_req.sid;
@@ -941,22 +1064,41 @@ static int ctldev_handle(void)
 		sid = ev->r.connerror.sid;
 		cid = ev->r.connerror.cid;
 		break;
+	case ISCSI_KEVENT_CONN_LOGIN_STATE:
+		sid = ev->r.conn_login.sid;
+		cid = ev->r.conn_login.cid;
+		state = ev->r.conn_login.state;
+		break;
 	case ISCSI_KEVENT_UNBIND_SESSION:
 		sid = ev->r.unbind_session.sid;
 		/* session wide event so cid is 0 */
 		cid = 0;
 		break;
 	default:
-		log_error("Unknown kernel event %d. You may want to upgrade "
-			  "your iscsi tools.", ev->type);
+		if ((ev->type > ISCSI_UEVENT_MAX && ev->type < KEVENT_BASE) ||
+		    (ev->type > ISCSI_KEVENT_MAX))
+			log_error("Unknown kernel event %d. You may want to "
+				  " upgrade your iscsi tools.", ev->type);
+		else
+			/*
+			 * If another app is using the interface we might
+			 * see their
+			 * stuff. Just drop it.
+			 */
+			log_debug(7, "Got unknwon event %d. Dropping.",
+				  ev->type);
 		drop_data(nlh);
-		return -EINVAL;
+		return 0;
 	}
 
 	/* verify connection */
 	session = session_find_by_sid(sid);
 	if (!session) {
-		log_error("Could not verify connection %d:%d. Dropping "
+		/*
+		 * this can happen normally when other apps are using the
+		 * nl interface.
+		 */
+		log_debug(1, "Could not verify connection %d:%d. Dropping "
 			   "event.\n", sid, cid);
 		drop_data(nlh);
 		return -ENXIO;
@@ -964,19 +1106,20 @@ static int ctldev_handle(void)
 	conn = &session->conn[0];
 
 	ev_size = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct nlmsghdr));
-	conn_context = iscsi_conn_context_get(conn, ev_size);
-	if (!conn_context) {
+
+	ev_context = ipc_ev_clbk->get_ev_context(conn, ev_size);
+	if (!ev_context) {
 		/* retry later */
 		log_error("Can not allocate memory for receive context.");
 		return -ENOMEM;
 	}
 
 	log_debug(6, "message real length is %d bytes, recv_handle %p",
-		nlh->nlmsg_len, conn_context->data);
+		nlh->nlmsg_len, ev_context->data);
 
-	if ((rc = nlpayload_read(ctrl_fd, conn_context->data,
+	if ((rc = nlpayload_read(ctrl_fd, ev_context->data,
 				ev_size, 0)) < 0) {
-		iscsi_conn_context_put(conn_context);
+		ipc_ev_clbk->put_ev_context(ev_context);
 		log_error("can not read from NL socket, error %d", rc);
 		/* retry later */
 		return rc;
@@ -988,26 +1131,34 @@ static int ctldev_handle(void)
 	 */
 	switch (ev->type) {
 	case ISCSI_KEVENT_RECV_PDU:
-		iscsi_sched_conn_context(conn_context, conn, 0,
-					 EV_CONN_RECV_PDU);
+		rc = ipc_ev_clbk->sched_ev_context(ev_context, conn, 0,
+						   EV_CONN_RECV_PDU);
 		break;
 	case ISCSI_KEVENT_CONN_ERROR:
-		memcpy(conn_context->data, &ev->r.connerror.error,
+		memcpy(ev_context->data, &ev->r.connerror.error,
 			sizeof(ev->r.connerror.error));
-		iscsi_sched_conn_context(conn_context, conn, 0,
-					 EV_CONN_ERROR);
+		rc = ipc_ev_clbk->sched_ev_context(ev_context, conn, 0,
+						   EV_CONN_ERROR);
+		break;
+	case ISCSI_KEVENT_CONN_LOGIN_STATE:
+		memcpy(ev_context->data, &ev->r.conn_login.state,
+			sizeof(ev->r.conn_login.state));
+		rc = ipc_ev_clbk->sched_ev_context(ev_context, conn, 0,
+						   EV_CONN_LOGIN);
 		break;
 	case ISCSI_KEVENT_UNBIND_SESSION:
-		iscsi_sched_conn_context(conn_context, conn, 0,
-					 EV_CONN_STOP);
+		rc = ipc_ev_clbk->sched_ev_context(ev_context, conn, 0,
+						   EV_CONN_STOP);
 		break;
 	default:
-		iscsi_conn_context_put(conn_context);
+		ipc_ev_clbk->put_ev_context(ev_context);
 		log_error("unknown kernel event %d", ev->type);
 		return -EEXIST;
 	}
 
-	return 0;
+	if (rc)
+		ipc_ev_clbk->put_ev_context(ev_context);
+	return rc;
 }
 
 static int
@@ -1114,5 +1265,12 @@ struct iscsi_ipc nl_ipc = {
 	.read			= kread,
 	.recv_pdu_begin         = krecv_pdu_begin,
 	.recv_pdu_end           = krecv_pdu_end,
+	.set_net_config         = kset_net_config,
+	.recv_conn_state        = krecv_conn_state,
 };
 struct iscsi_ipc *ipc = &nl_ipc;
+
+void ipc_register_ev_callback(struct iscsi_ipc_ev_clbk *ev_clbk)
+{
+	ipc_ev_clbk = ev_clbk;
+}
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/session_info.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_info.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/session_info.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_info.c	2011-08-14 16:48:25.000000000 -0500
@@ -13,6 +13,7 @@
 #include "initiator.h"
 #include "iface.h"
 #include "iscsid_req.h"
+#include "iscsi_err.h"
 
 int session_info_create_list(void *data, struct session_info *info)
 {
@@ -25,7 +26,7 @@ int session_info_create_list(void *data,
 
 	new = calloc(1, sizeof(*new));
 	if (!new)
-		return ENOMEM;
+		return ISCSI_ERR_NOMEM;
 	memcpy(new, info, sizeof(*new));
 	INIT_LIST_HEAD(&new->list);
 
@@ -113,7 +114,7 @@ static int print_iscsi_state(int sid, ch
 	 * anything here since it does not know about it.
 	 */
 	if (!err && rsp.u.session_state.conn_state >= 0 &&
-	    rsp.u.session_state.conn_state <= STATE_CLEANUP_WAIT)
+	    rsp.u.session_state.conn_state <= ISCSI_CONN_STATE_CLEANUP_WAIT)
 		state = conn_state[rsp.u.session_state.conn_state];
 	printf("%s\t\tiSCSI Connection State: %s\n", prefix,
 	       state ? state : "Unknown");
@@ -223,7 +224,7 @@ static int print_scsi_state(int sid, cha
 }
 
 void session_info_print_tree(struct list_head *list, char *prefix,
-			     unsigned int flags)
+			     unsigned int flags, int do_show)
 {
 	struct session_info *curr, *prev = NULL;
 
@@ -277,6 +278,70 @@ void session_info_print_tree(struct list
 			printf("%s\t\tSID: %d\n", prefix, curr->sid);
 			print_iscsi_state(curr->sid, prefix);
 		}
+		if (flags & SESSION_INFO_ISCSI_TIM) {
+			printf("%s\t\t*********\n", prefix);
+			printf("%s\t\tTimeouts:\n", prefix);
+			printf("%s\t\t*********\n", prefix);
+
+			printf("%s\t\tRecovery Timeout: %d\n", prefix,
+			      ((curr->tmo).recovery_tmo));
+
+			if ((curr->tmo).tgt_reset_tmo >= 0)
+				printf("%s\t\tTarget Reset Timeout: %d\n",
+					prefix,
+					((curr->tmo).tgt_reset_tmo));
+			else
+				printf("%s\t\tTarget Reset Timeout: %s\n",
+					prefix, UNKNOWN_VALUE);
+
+			if ((curr->tmo).lu_reset_tmo >= 0)
+				printf("%s\t\tLUN Reset Timeout: %d\n", prefix,
+					((curr->tmo).lu_reset_tmo));
+			else
+				printf("%s\t\tLUN Reset Timeout: %s\n", prefix,
+					UNKNOWN_VALUE);
+
+			if ((curr->tmo).lu_reset_tmo >= 0)
+				printf("%s\t\tAbort Timeout: %d\n", prefix,
+					((curr->tmo).abort_tmo));
+			else
+				printf("%s\t\tAbort Timeout: %s\n", prefix,
+					UNKNOWN_VALUE);
+
+		}
+		if (flags & SESSION_INFO_ISCSI_AUTH) {
+			printf("%s\t\t*****\n", prefix);
+			printf("%s\t\tCHAP:\n", prefix);
+			printf("%s\t\t*****\n", prefix);
+			if (!do_show) {
+				strcpy(curr->chap.password, "********");
+				strcpy(curr->chap.password_in, "********");
+			}
+			if (strlen((curr->chap).username))
+				printf("%s\t\tusername: %s\n", prefix,
+					(curr->chap).username);
+			else
+				printf("%s\t\tusername: %s\n", prefix,
+					UNKNOWN_VALUE);
+			if (strlen((curr->chap).password))
+				printf("%s\t\tpassword: %s\n", prefix,
+					(curr->chap).password);
+			else
+				printf("%s\t\tpassword: %s\n", prefix,
+					UNKNOWN_VALUE);
+			if (strlen((curr->chap).username_in))
+				printf("%s\t\tusername_in: %s\n", prefix,
+					(curr->chap).username_in);
+			else
+				printf("%s\t\tusername_in: %s\n", prefix,
+					UNKNOWN_VALUE);
+			if (strlen((curr->chap).password_in))
+				printf("%s\t\tpassword_in: %s\n", prefix,
+					(curr->chap).password_in);
+			else
+				printf("%s\t\tpassword_in: %s\n", prefix,
+					UNKNOWN_VALUE);
+		}
 
 		if (flags & SESSION_INFO_ISCSI_PARAMS)
 			print_iscsi_params(curr->sid, prefix);
@@ -288,7 +353,7 @@ void session_info_print_tree(struct list
 	}
 }
 
-int session_info_print(int info_level, struct session_info *info)
+int session_info_print(int info_level, struct session_info *info, int do_show)
 {
 	struct list_head list;
 	int num_found = 0, err = 0;
@@ -316,17 +381,18 @@ int session_info_print(int info_level, s
 		flags |= (SESSION_INFO_SCSI_DEVS | SESSION_INFO_HOST_DEVS);
 		/* fall through */
 	case 2:
-		flags |= SESSION_INFO_ISCSI_PARAMS;
+		flags |= (SESSION_INFO_ISCSI_PARAMS | SESSION_INFO_ISCSI_TIM
+				| SESSION_INFO_ISCSI_AUTH);
 		/* fall through */
 	case 1:
 		INIT_LIST_HEAD(&list);
 		struct session_link_info link_info;
 
-		flags |= (SESSION_INFO_ISCSI_STATE |SESSION_INFO_IFACE);
+		flags |= (SESSION_INFO_ISCSI_STATE | SESSION_INFO_IFACE);
 		if (info) {
 			INIT_LIST_HEAD(&info->list);
 			list_add_tail(&list, &info->list);
-			session_info_print_tree(&list, "", flags);
+			session_info_print_tree(&list, "", flags, do_show);
 			num_found = 1;
 			break;
 		}
@@ -341,18 +407,20 @@ int session_info_print(int info_level, s
 		if (err || !num_found)
 			break;
 
-		session_info_print_tree(&list, "", flags);
+		session_info_print_tree(&list, "", flags, do_show);
 		session_info_free_list(&list);
 		break;
 	default:
 		log_error("Invalid info level %d. Try 0 - 3.", info_level);
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 	}
 
 	if (err) {
 		log_error("Can not get list of active sessions (%d)", err);
 		return err;
-	} else if (!num_found)
+	} else if (!num_found) {
 		log_error("No active sessions.");
+		return ISCSI_ERR_NO_OBJS_FOUND;
+	}
 	return 0;
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/session_info.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_info.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/session_info.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_info.h	2011-08-14 16:48:25.000000000 -0500
@@ -9,12 +9,29 @@
 
 struct list;
 
+struct session_timeout {
+	int abort_tmo;
+	int lu_reset_tmo;
+	int recovery_tmo;
+	int tgt_reset_tmo;
+};
+
+struct session_CHAP {
+	char username[AUTH_STR_MAX_LEN];
+	char password[AUTH_STR_MAX_LEN];
+	char username_in[AUTH_STR_MAX_LEN];
+	char password_in[AUTH_STR_MAX_LEN];
+};
+
 struct session_info {
 	struct list_head list;
 	/* local info */
 	struct iface_rec iface;
 	int sid;
 
+	struct session_timeout tmo;
+	struct session_CHAP chap;
+
 	/* remote info */
 	char targetname[TARGET_NAME_MAXLEN + 1];
 	int tpgt;
@@ -37,11 +54,14 @@ struct session_link_info {
 #define SESSION_INFO_ISCSI_STATE	0x4
 #define SESSION_INFO_SCSI_DEVS		0x8
 #define SESSION_INFO_HOST_DEVS		0x10
+#define SESSION_INFO_ISCSI_TIM          0x20
+#define SESSION_INFO_ISCSI_AUTH         0x40
 
 extern int session_info_create_list(void *data, struct session_info *info);
 extern void session_info_free_list(struct list_head *list);
-extern int session_info_print(int info_level, struct session_info *match_info);
+extern int session_info_print(int info_level, struct session_info *match_info,
+				int do_show);
 extern void session_info_print_tree(struct list_head *list, char *prefix,
-				    unsigned int flags);
+				    unsigned int flags, int do_show);
 
 #endif
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/session_mgmt.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_mgmt.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/session_mgmt.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_mgmt.c	2011-08-14 16:48:25.000000000 -0500
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2010 Mike Christie
  * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
-
+ * Copyright (C) 2011 Dell Inc.
  * maintained by open-iscsi@googlegroups.com
  *
  * This program is free software; you can redistribute it and/or modify
@@ -32,6 +32,7 @@
 #include "iscsi_sysfs.h"
 #include "log.h"
 #include "iscsid_req.h"
+#include "iscsi_err.h"
 
 static void log_login_msg(struct node_rec *rec, int rc)
 {
@@ -40,7 +41,7 @@ static void log_login_msg(struct node_re
 			  "portal: %s,%d].", rec->iface.name,
 			  rec->name, rec->conn[0].address,
 			  rec->conn[0].port);
-		iscsid_handle_error(rc);
+		iscsi_err_print_msg(rc);
 	} else
 		log_info("Login to [iface: %s, target: %s, portal: "
 			 "%s,%d] successful.", rec->iface.name,
@@ -82,6 +83,8 @@ static int iscsid_login_reqs_wait(struct
 
 		rec = curr->data;
 		err = iscsid_req_wait(MGMT_IPC_SESSION_LOGIN, curr->fd);
+		if (err && !ret)
+			ret = err;
 		log_login_msg(rec, err);
 		list_del(&curr->list);
 		free(curr);
@@ -90,19 +93,27 @@ static int iscsid_login_reqs_wait(struct
 }
 
 /**
- * iscsi_login_portal - request iscsid to login to portal
- * @data: Unused. Only needed so this can be used in iscsi_login_portals
+ * __iscsi_login_portal - request iscsid to login to portal
+ * @data: If set, copies the session.multiple value to the portal record
+ *        so it is propagated to iscsid.
  * @list: If async, list to add session to
  * @rec: portal rec to log into
  */
-int iscsi_login_portal(void *data, struct list_head *list, struct node_rec *rec)
+static int
+__iscsi_login_portal(void *data, struct list_head *list, struct node_rec *rec)
 {
 	struct iscsid_async_req *async_req = NULL;
 	int rc = 0, fd;
 
-	log_info("Logging in to [iface: %s, target: %s, portal: %s,%d]",
+	if (data && !rec->session.multiple) {
+		struct node_rec *pattern_rec = data;
+		rec->session.multiple = pattern_rec->session.multiple;
+	}
+
+	log_info("Logging in to [iface: %s, target: %s, portal: %s,%d]%s",
 		 rec->iface.name, rec->name, rec->conn[0].address,
-		 rec->conn[0].port);
+		 rec->conn[0].port,
+		 (rec->session.multiple ? " (multiple)" : ""));
 
 	if (list) {
 		async_req = calloc(1, sizeof(*async_req));
@@ -123,11 +134,7 @@ int iscsi_login_portal(void *data, struc
 		log_login_msg(rec, rc);
 		if (async_req)
 			free(async_req);
-		/* we raced with another app or instance of iscsiadm */
-		if (rc == MGMT_IPC_ERR_EXISTS)
-			return 0;
-
-		return ENOTCONN;
+		return rc;
 	}
 
 	if (async_req) {
@@ -141,6 +148,63 @@ int iscsi_login_portal(void *data, struc
 }
 
 /**
+ * iscsi_login_portal - request iscsid to login to portal multiple
+ * times, based on the session.nr_sessions in the portal record.
+ * @data: If set, session.multiple will cause an additional session to
+ *        be created regardless of the value of session.nr_sessions
+ * @list: If async, list to add session to
+ * @rec: portal rec to log into
+ */
+int iscsi_login_portal(void *data, struct list_head *list, struct node_rec *rec)
+{
+	struct node_rec *pattern_rec = data;
+	int rc = 0, session_count = 0, i;
+
+	/*
+	 * If pattern_rec->session.multiple is set, just add a single new
+	 * session by passing things along to __iscsi_login_portal
+	 */
+	if (pattern_rec && pattern_rec->session.multiple)
+		return __iscsi_login_portal(data, list, rec);
+
+	/*
+	 * Count the current number of sessions, and only create those
+	 * that are missing.
+	 */
+	rc = iscsi_sysfs_for_each_session(rec, &session_count,
+					  iscsi_match_session_count);
+	if (rc) {
+		log_error("Could not count current number of sessions");
+		goto done;
+	}
+	if (session_count >= rec->session.nr_sessions) {
+		log_debug(1, "%s: %d session%s requested, but %d "
+			  "already present.",
+			  rec->iface.name, rec->session.nr_sessions,
+			  rec->session.nr_sessions == 1 ? "" : "s",
+			  session_count);
+		rc = 0;
+		goto done;
+	}
+
+	/*
+	 * Ensure the record's 'multiple' flag is set so __iscsi_login_portal
+	 * will allow multiple logins.
+	 */
+	rec->session.multiple = 1;
+	for (i = session_count; i < rec->session.nr_sessions; ++i) {
+		log_debug(1, "%s: Creating session %d/%d", rec->iface.name,
+			  i + 1, rec->session.nr_sessions);
+		int err = __iscsi_login_portal(pattern_rec, list, rec);
+		if (err && !rc)
+			rc = err;
+	}
+
+done:
+	return rc;
+}
+
+/**
  * iscsi_login_portal_nowait - request iscsid to login to portal
  * @rec: portal rec to log into
  *
@@ -152,7 +216,6 @@ int iscsi_login_portal_nowait(struct nod
 	int err;
 
 	INIT_LIST_HEAD(&list);
-
 	err = iscsi_login_portal(NULL, &list, rec);
 	if (err > 0)
 		return err;
@@ -161,20 +224,22 @@ int iscsi_login_portal_nowait(struct nod
 }
 
 /**
- * iscsi_login_portals - login into portals on @rec_list,
+ * __iscsi_login_portals - login into portals on @rec_list,
  * @data: data to pass to login_fn
  * @nr_found: returned with number of portals logged into
  * @wait: bool indicating if the fn should wait for the result
  * @rec_list: list of portals to log into
+ * @clear_list: If set, delete and free rec_list after iterating through.
  * @login_fn: list iter function
  *
  * This will loop over the list of portals and login. It
  * will attempt to login asynchronously, and then wait for
  * them to complete if wait is set.
  */
-int iscsi_login_portals(void *data, int *nr_found, int wait,
-			struct list_head *rec_list,
-			int (* login_fn)(void *, struct list_head *,
+static
+int __iscsi_login_portals(void *data, int *nr_found, int wait,
+			struct list_head *rec_list, int clear_list,
+			int (*login_fn)(void *, struct list_head *,
 					 struct node_rec *))
 {
 	struct node_rec *curr_rec, *tmp;
@@ -191,7 +256,6 @@ int iscsi_login_portals(void *data, int 
 		if (!err)
 			(*nr_found)++;
 	}
-
 	if (wait) {
 		err = iscsid_login_reqs_wait(&login_list);
 		if (err && !ret)
@@ -199,13 +263,50 @@ int iscsi_login_portals(void *data, int 
 	} else
 		iscsid_reqs_close(&login_list);
 
-	list_for_each_entry_safe(curr_rec, tmp, rec_list, list) {
-		list_del(&curr_rec->list);
-		free(curr_rec);
+	if (clear_list) {
+		list_for_each_entry_safe(curr_rec, tmp, rec_list, list) {
+			list_del(&curr_rec->list);
+			free(curr_rec);
+		}
 	}
 	return ret;
 }
 
+/**
+ * iscsi_login_portals - login into portals on @rec_list,
+ * @data: data to pass to login_fn
+ * @nr_found: returned with number of portals logged into
+ * @wait: bool indicating if the fn should wait for the result
+ * @rec_list: list of portals to log into.  This list is deleted after
+ *            iterating through it.
+ * @login_fn: list iter function
+ *
+ * This will loop over the list of portals and login. It
+ * will attempt to login asynchronously, and then wait for
+ * them to complete if wait is set.
+ */
+int iscsi_login_portals(void *data, int *nr_found, int wait,
+			struct list_head *rec_list,
+			int (*login_fn)(void *, struct list_head *,
+					 struct node_rec *))
+{
+	return __iscsi_login_portals(data, nr_found, wait, rec_list,
+				     1, login_fn);
+}
+
+/**
+ * iscsi_login_portals_safe - login into portals on @rec_list, but do not
+ *			      clear out rec_list.
+ */
+int iscsi_login_portals_safe(void *data, int *nr_found, int wait,
+			struct list_head *rec_list,
+			int (*login_fn)(void *, struct list_head *,
+					 struct node_rec *))
+{
+	return __iscsi_login_portals(data, nr_found, wait, rec_list,
+				     0, login_fn);
+}
+
 static void log_logout_msg(struct session_info *info, int rc)
 {
 	if (rc) {
@@ -213,7 +314,7 @@ static void log_logout_msg(struct sessio
 			  "portal: %s,%d].", info->sid,
 			  info->targetname,
 			  info->persistent_address, info->port);
-		iscsid_handle_error(rc);
+		iscsi_err_print_msg(rc);
 	} else
 		log_info("Logout of [sid: %d, target: %s, "
 			 "portal: %s,%d] successful.",
@@ -277,11 +378,7 @@ int iscsi_logout_portal(struct session_i
 		log_logout_msg(info, rc);
 		if (async_req)
 			free(async_req);
-
-		if (rc == MGMT_IPC_ERR_NOT_FOUND)
-			return 0;
-
-		return EIO;
+		return rc;
 	}
 
 	if (async_req) {
@@ -325,10 +422,17 @@ int iscsi_logout_portals(void *data, int
 
 	err = iscsi_sysfs_for_each_session(&link_info, nr_found,
 					   session_info_create_list);
-	if (err || !*nr_found)
+	if (err && !list_empty(&session_list))
+		log_error("Could not read in all sessions: %s",
+			  iscsi_err_to_str(err));
+	else if (err && list_empty(&session_list)) {
+		log_error("Could not read session info.");
 		return err;
-
+	} else if (list_empty(&session_list))
+		return ISCSI_ERR_NO_OBJS_FOUND;
+	ret = err;
 	*nr_found = 0;
+
 	list_for_each_entry(curr_info, &session_list, list) {
 		err = logout_fn(data, &logout_list, curr_info);
 		if (err > 0 && !ret)
@@ -337,13 +441,22 @@ int iscsi_logout_portals(void *data, int
 			(*nr_found)++;
 	}
 
+	if (!*nr_found) {
+		ret = ISCSI_ERR_NO_OBJS_FOUND;
+		goto free_list;
+	}
+
 	if (wait) {
 		err = iscsid_logout_reqs_wait(&logout_list);
-		if (err)
+		if (err && !ret)
 			ret = err;
 	} else
 		iscsid_reqs_close(&logout_list);
 
+	if (ret)
+		log_error("Could not logout of all requested sessions");
+
+free_list:
 	session_info_free_list(&session_list);
 	return ret;
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/session_mgmt.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_mgmt.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/session_mgmt.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/session_mgmt.h	2011-08-14 16:48:25.000000000 -0500
@@ -10,7 +10,11 @@ extern int iscsi_login_portal(void *data
 extern int iscsi_login_portal_nowait(struct node_rec *rec);
 extern int iscsi_login_portals(void *data, int *nr_found, int wait,
 			       struct list_head *rec_list,
-			       int (* login_fn)(void *, struct list_head *,
+			       int (*login_fn)(void *, struct list_head *,
+						struct node_rec *));
+extern int iscsi_login_portals_safe(void *data, int *nr_found, int wait,
+			       struct list_head *rec_list,
+			       int (*login_fn)(void *, struct list_head *,
 						struct node_rec *));
 extern int iscsi_logout_portal(struct session_info *info,
 			       struct list_head *list);
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/sysfs.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/sysfs.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/sysfs.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/sysfs.c	2011-08-14 16:48:25.000000000 -0500
@@ -547,7 +547,7 @@ found:
 }
 
 
-char *sysfs_get_value(char *id, char *subsys, char *param)
+char *sysfs_get_value(const char *id, char *subsys, char *param)
 {
 	char devpath[PATH_SIZE];
 	char *sysfs_value;
@@ -590,7 +590,7 @@ int sysfs_get_uint(char *id, char *subsy
 	return 0;
 }
 
-int sysfs_get_int(char *id, char *subsys, char *param, int *value)
+int sysfs_get_int(const char *id, char *subsys, char *param, int *value)
 {
 	char *sysfs_value;
 
@@ -636,6 +636,34 @@ int sysfs_get_uint64(char *id, char *sub
 	return 0;
 }
 
+int sysfs_get_uint8(char *id, char *subsys, char *param,
+		    uint8_t *value)
+{
+	char *sysfs_value;
+
+	*value = -1;
+	sysfs_value = sysfs_get_value(id, subsys, param);
+	if (!sysfs_value)
+		return EIO;
+
+	*value = (uint8_t)atoi(sysfs_value);
+	return 0;
+}
+
+int sysfs_get_uint16(char *id, char *subsys, char *param,
+		     uint16_t *value)
+{
+	char *sysfs_value;
+
+	*value = -1;
+	sysfs_value = sysfs_get_value(id, subsys, param);
+	if (!sysfs_value)
+		return EIO;
+
+	*value = (uint16_t)atoi(sysfs_value);
+	return 0;
+}
+
 int sysfs_set_param(char *id, char *subsys, char *attr_name,
 		    char *write_buf, ssize_t buf_size)
 {
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/sysfs.h open-iscsi-2.0-872-rc4-bnx2i.sync/usr/sysfs.h
--- open-iscsi-2.0-872-rc4-bnx2i/usr/sysfs.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/sysfs.h	2011-08-14 16:48:25.000000000 -0500
@@ -51,14 +51,18 @@ extern char *sysfs_attr_get_value(const 
 extern int sysfs_resolve_link(char *path, size_t size);
 extern int sysfs_lookup_devpath_by_subsys_id(char *devpath, size_t len, const char *subsystem, const char *id);
 
-extern char *sysfs_get_value(char *id, char *subsys, char *param);
+extern char *sysfs_get_value(const char *id, char *subsys, char *param);
 extern int sysfs_get_uint(char *id, char *subsys, char *param,
 			  unsigned int *value);
-extern int sysfs_get_int(char *id, char *subsys, char *param, int *value);
+extern int sysfs_get_int(const char *id, char *subsys, char *param, int *value);
 extern int sysfs_get_str(char *id, char *subsys, char *param, char *value,
 			 int value_size);
 extern int sysfs_get_uint64(char *id, char *subsys, char *param,
 			    uint64_t *value);
+extern int sysfs_get_uint8(char *id, char *subsys, char *param,
+			   uint8_t *value);
+extern int sysfs_get_uint16(char *id, char *subsys, char *param,
+			    uint16_t *value);
 extern int sysfs_set_param(char *id, char *subsys, char *attr_name,
 			   char *write_buf, ssize_t buf_size);
 
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/usr/transport.c open-iscsi-2.0-872-rc4-bnx2i.sync/usr/transport.c
--- open-iscsi-2.0-872-rc4-bnx2i/usr/transport.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/usr/transport.c	2011-08-14 16:48:25.000000000 -0500
@@ -25,7 +25,7 @@
 #include "log.h"
 #include "iscsi_util.h"
 #include "iscsi_sysfs.h"
-#include "cxgb3i.h"
+#include "cxgbi.h"
 #include "be2iscsi.h"
 
 struct iscsi_transport_template iscsi_tcp = {
@@ -49,7 +49,16 @@ struct iscsi_transport_template cxgb3i =
 	.ep_connect	= ktransport_ep_connect,
 	.ep_poll	= ktransport_ep_poll,
 	.ep_disconnect	= ktransport_ep_disconnect,
-	.create_conn	= cxgb3i_create_conn,
+	.create_conn	= cxgbi_create_conn,
+};
+
+struct iscsi_transport_template cxgb4i = {
+	.name		= "cxgb4i",
+	.set_host_ip	= 1,
+	.ep_connect	= ktransport_ep_connect,
+	.ep_poll	= ktransport_ep_poll,
+	.ep_disconnect	= ktransport_ep_disconnect,
+	.create_conn	= cxgbi_create_conn,
 };
 
 struct iscsi_transport_template bnx2i = {
@@ -70,12 +79,17 @@ struct iscsi_transport_template be2iscsi
 
 struct iscsi_transport_template qla4xxx = {
 	.name		= "qla4xxx",
+	.set_host_ip	= 0,
+	.ep_connect	= ktransport_ep_connect,
+	.ep_poll	= ktransport_ep_poll,
+	.ep_disconnect	= ktransport_ep_disconnect,
 };
 
 static struct iscsi_transport_template *iscsi_transport_templates[] = {
 	&iscsi_tcp,
 	&iscsi_iser,
 	&cxgb3i,
+	&cxgb4i,
 	&bnx2i,
 	&qla4xxx,
 	&be2iscsi,
@@ -97,6 +111,7 @@ int set_transport_template(struct iscsi_
 		}
 	}
 
-	log_error("Could not find uspace transport for %s\n", t->name);
+	log_error("Could not find template for %s. An updated iscsiadm "
+		  "is probably needed.\n", t->name);
 	return ENOSYS;
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/fw_entry.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/fw_entry.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/fw_entry.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/fw_entry.c	2011-08-14 16:48:25.000000000 -0500
@@ -34,6 +34,7 @@
 #include "fwparam.h"
 #include "idbm_fields.h"
 #include "iscsi_net_util.h"
+#include "iscsi_err.h"
 
 /**
  * fw_setup_nics - setup nics (ethXs) based on ibft net info
@@ -56,7 +57,7 @@ int fw_setup_nics(void)
 	ret = fw_get_targets(&targets);
 	if (ret || list_empty(&targets)) {
 		printf("Could not setup fw entries.\n");
-		return ENODEV;
+		return ISCSI_ERR_NO_OBJS_FOUND;
 	}
 
 	/*
@@ -85,7 +86,10 @@ int fw_setup_nics(void)
 	}
 
 	fw_free_targets(&targets);
-	return ret;
+	if (ret)
+		return ISCSI_ERR;
+	else
+		return 0;
 }
 
 /**
@@ -196,7 +200,7 @@ static void dump_network(struct boot_con
 	if (strlen(context->secondary_dns))
 		printf("%s = %s\n", IFACE_SEC_DNS, context->secondary_dns);
 	if (strlen(context->vlan))
-		printf("%s = %s\n", IFACE_VLAN, context->vlan);
+		printf("%s = %s\n", IFACE_VLAN_ID, context->vlan);
 	if (strlen(context->iface))
 		printf("%s = %s\n", IFACE_NETNAME, context->iface);
 }
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/fwparam_ppc.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/fwparam_ppc.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/fwparam_ppc.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/fwparam_ppc.c	2011-08-14 16:48:25.000000000 -0500
@@ -30,6 +30,7 @@
 #include "iscsi_obp.h"
 #include "prom_parse.h"
 #include "sysdeps.h"
+#include "iscsi_err.h"
 
 void* yy_scan_string(const char *str);
 int yyparse(struct ofw_dev *ofwdev);
@@ -355,7 +356,7 @@ static int loop_devs(const char *devtree
 	 * Sort the nics into "natural" order.	The proc fs
 	 * device-tree has them in somewhat random, or reversed order.
 	 */
-	qsort(niclist, nic_count, sizeof(char *), nic_cmp);
+	qsort(niclist, nic_count, sizeof(char *), (__compar_fn_t)nic_cmp);
 
 	snprintf(prefix, sizeof(prefix), "%s/%s", devtree, "aliases");
 	dev_count = 0;
@@ -449,7 +450,7 @@ int fwparam_ppc_boot_info(struct boot_co
 
 	devtree = find_devtree(filename);
 	if (!devtree)
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 
 	/*
 	 * Always search the device-tree to find the capable nic devices.
@@ -459,7 +460,7 @@ int fwparam_ppc_boot_info(struct boot_co
 		goto free_devtree;
 
 	if (find_file(filename) < 1)
-		error = ENODEV;
+		error = ISCSI_ERR_NO_OBJS_FOUND;
 	else {
 		if (debug)
 			printf("%s:\n%s\n\n", filename, bootpath_val);
@@ -469,12 +470,12 @@ int fwparam_ppc_boot_info(struct boot_co
 		 */
 
 		if (!strstr(bootpath_val, "iscsi")) {
-			error = EINVAL;
+			error = ISCSI_ERR_INVAL;
 			goto free_devtree;
 		}
 		ofwdevs[0] = calloc(1, sizeof(struct ofw_dev));
 		if (!ofwdevs[0]) {
-			error = ENOMEM;
+			error = ISCSI_ERR_NOMEM;
 			goto free_devtree;
 		}
 
@@ -484,7 +485,7 @@ int fwparam_ppc_boot_info(struct boot_co
 		if (!error) {
 			context = calloc(1, sizeof(*context));
 			if (!context)
-				error = ENOMEM;
+				error = ISCSI_ERR_NOMEM;
 			else
 				fill_context(context, ofwdevs[0]);
 		}
@@ -524,7 +525,7 @@ int fwparam_ppc_get_targets(struct list_
 
 	devtree = find_devtree(filename);
 	if (!devtree)
-		return EINVAL;
+		return ISCSI_ERR_INVAL;
 
 	/*
 	 * Always search the device-tree to find the capable nic devices.
@@ -534,7 +535,7 @@ int fwparam_ppc_get_targets(struct list_
 		goto free_devtree;
 
 	if (find_file(filename) < 1)
-		error = ENODEV;
+		error = ISCSI_ERR_NO_OBJS_FOUND;
 	else {
 		if (debug)
 			printf("%s:\n%s\n\n", filename, bootpath_val);
@@ -544,12 +545,12 @@ int fwparam_ppc_get_targets(struct list_
 		 */
 
 		if (!strstr(bootpath_val, "iscsi")) {
-			error = EINVAL;
+			error = ISCSI_ERR_INVAL;
 			goto free_devtree;
 		}
 		ofwdevs[0] = calloc(1, sizeof(struct ofw_dev));
 		if (!ofwdevs[0]) {
-			error = ENOMEM;
+			error = ISCSI_ERR_NOMEM;
 			goto free_devtree;
 		}
 
@@ -559,7 +560,7 @@ int fwparam_ppc_get_targets(struct list_
 		if (!error) {
 			context = calloc(1, sizeof(*context));
 			if (!context)
-				error = ENOMEM;
+				error = ISCSI_ERR_NOMEM;
 			else {
 				fill_context(context, ofwdevs[0]);
 				list_add_tail(&context->list, list);
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/fwparam_sysfs.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/fwparam_sysfs.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/fwparam_sysfs.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/fwparam_sysfs.c	2011-08-14 16:48:25.000000000 -0500
@@ -36,6 +36,7 @@
 #include "fwparam.h"
 #include "sysdeps.h"
 #include "iscsi_net_util.h"
+#include "iscsi_err.h"
 
 #define ISCSI_BOOT_MAX		255
 #define IBFT_SYSFS_ROOT		"/sys/firmware/ibft/"
@@ -351,7 +352,7 @@ int fwparam_sysfs_boot_info(struct boot_
 	 */
 	dirfd = opendir(ISCSI_LLD_ROOT);
 	if (!dirfd)
-		return errno;
+		return ISCSI_ERR_SYSFS_LOOKUP;
 
 	while ((dent = readdir(dirfd))) {
 		char lld_root[FILENAMESZ];
@@ -364,12 +365,12 @@ int fwparam_sysfs_boot_info(struct boot_
 		if (strncmp(dent->d_name, ISCSI_LLD_SUBSYS_PREFIX, 10))
 			continue;
 
-		snprintf(lld_root, FILENAMESZ, ISCSI_LLD_ROOT"%s",
+		snprintf(lld_root, FILENAMESZ, ISCSI_LLD_ROOT"%s/",
 			 dent->d_name);
 		if (!get_boot_info(context, lld_root, dent->d_name))
 			goto done;
 	}
-	rc = ENODEV;
+	rc = ISCSI_ERR_NO_OBJS_FOUND;
 done:
 	closedir(dirfd);
 	return rc;
@@ -401,12 +402,12 @@ static int get_targets(struct list_head 
 
 		rc = fill_tgt_context(subsys, target_list[i], context);
 		if (rc)
-			break;
+			goto cleanup;
 
 		rc = sysfs_get_int(target_list[i], subsys, "nic-assoc",
 				   &nic_idx);
 		if (rc)
-			break;
+			goto cleanup;
 
 		for (nic = 0; nic < nic_cnt; nic++) {
 			int id;
@@ -420,21 +421,31 @@ static int get_targets(struct list_head 
 		if (nic == nic_cnt) {
 			printf("Invalid nic-assoc of %d. Max id %d.\n",
 			       nic_idx, nic_cnt);
-			break;
+			goto cleanup;
 		}
 
 		rc = fill_nic_context(subsys, nic_list[nic], context);
 		if (rc)
-			break;
+			goto cleanup;
 
 		fill_initiator_context(subsys, context);
 		list_add_tail(&context->list, list);
+		continue;
+cleanup:
+		free(context);
+		context = NULL;
 	}
 
 	if (rc) {
 		if (context)
 			free(context);
-		fw_free_targets(list);
+		/*
+		 * If there are some valid targets return them. Most likely,
+		 * the driver/ibft-implementation reported partial info
+		 * for targets/initiators that were not used for boot.
+		 */
+		if (!list_empty(list))
+			rc = 0;
 	}
 
 	deallocate_lists();
@@ -455,7 +466,7 @@ int fwparam_sysfs_get_targets(struct lis
 	 */
 	dirfd = opendir(ISCSI_LLD_ROOT);
 	if (!dirfd) {
-		rc = errno;
+		rc = ISCSI_ERR_SYSFS_LOOKUP;
 		goto done;
 	}
 
@@ -463,21 +474,20 @@ int fwparam_sysfs_get_targets(struct lis
 		char lld_root[FILENAMESZ];
 
 		memset(&lld_root, 0 , FILENAMESZ);
-
 		if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
 			continue;
 
 		if (strncmp(dent->d_name, ISCSI_LLD_SUBSYS_PREFIX, 10))
 			continue;
 
-		snprintf(lld_root, FILENAMESZ, ISCSI_LLD_ROOT"%s",
+		snprintf(lld_root, FILENAMESZ, ISCSI_LLD_ROOT"%s/",
 			 dent->d_name);
 		get_targets(list, lld_root, dent->d_name);
 	}
 	closedir(dirfd);
 done:
 	if (!rc && list_empty(list))
-		rc = ENODEV;
+		rc = ISCSI_ERR_NO_OBJS_FOUND;
 	if (rc)
 		fw_free_targets(list);
 	return rc;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/prom_lex.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/prom_lex.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/prom_lex.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/prom_lex.c	2011-08-14 16:48:25.000000000 -0500
@@ -8,7 +8,7 @@
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 33
+#define YY_FLEX_SUBMINOR_VERSION 35
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
@@ -30,7 +30,7 @@
 
 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
 
-#if __STDC_VERSION__ >= 199901L
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
 
 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
  * if you want the limit (max/min) macros for int types. 
@@ -53,7 +53,6 @@ typedef int flex_int32_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
-#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -84,6 +83,8 @@ typedef unsigned int flex_uint32_t;
 #define UINT32_MAX             (4294967295U)
 #endif
 
+#endif /* ! C99 */
+
 #endif /* ! FLEXINT_H */
 
 #ifdef __cplusplus
@@ -93,11 +94,12 @@ typedef unsigned int flex_uint32_t;
 
 #else	/* ! __cplusplus */
 
-#if __STDC__
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
 
 #define YY_USE_CONST
 
-#endif	/* __STDC__ */
+#endif	/* defined (__STDC__) */
 #endif	/* ! __cplusplus */
 
 #ifdef YY_USE_CONST
@@ -139,7 +141,15 @@ typedef unsigned int flex_uint32_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
 #define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
 #endif
 
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -177,14 +187,9 @@ extern FILE *yyin, *yyout;
 
 #define unput(c) yyunput( c, (yytext_ptr)  )
 
-/* The following is because we cannot portably get our hands on size_t
- * (without autoconf's help, which isn't available because we want
- * flex-generated scanners to compile on their own).
- */
-
 #ifndef YY_TYPEDEF_YY_SIZE_T
 #define YY_TYPEDEF_YY_SIZE_T
-typedef unsigned int yy_size_t;
+typedef size_t yy_size_t;
 #endif
 
 #ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -920,7 +925,7 @@ int yy_flex_debug = 0;
 #define YY_MORE_ADJ 0
 #define YY_RESTORE_YY_MORE_OFFSET
 #ifndef YYLMAX
-#define YYLMAX 2048
+#define YYLMAX 8192
 #endif
 
 char yytext[YYLMAX];
@@ -964,8 +969,9 @@ char *yytext_ptr;
 
 void dbgprint(const char *item) { fprintf(stderr, "%s: \"%s\" len=%d ", item, yytext, yyleng);}
 
+#define YY_NO_INPUT 1
 /* CHOSEN uses only boot related paths. */
-#line 969 "<stdout>"
+#line 975 "<stdout>"
 
 #define INITIAL 0
 
@@ -983,6 +989,35 @@ void dbgprint(const char *item) { fprint
 
 static int yy_init_globals (void );
 
+/* Accessor methods to globals.
+   These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy (void );
+
+int yyget_debug (void );
+
+void yyset_debug (int debug_flag  );
+
+YY_EXTRA_TYPE yyget_extra (void );
+
+void yyset_extra (YY_EXTRA_TYPE user_defined  );
+
+FILE *yyget_in (void );
+
+void yyset_in  (FILE * in_str  );
+
+FILE *yyget_out (void );
+
+void yyset_out  (FILE * out_str  );
+
+int yyget_leng (void );
+
+char *yyget_text (void );
+
+int yyget_lineno (void );
+
+void yyset_lineno (int line_number  );
+
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -995,8 +1030,6 @@ extern int yywrap (void );
 #endif
 #endif
 
-    static void yyunput (int c,char *buf_ptr  );
-    
 #ifndef yytext_ptr
 static void yy_flex_strncpy (char *,yyconst char *,int );
 #endif
@@ -1017,7 +1050,12 @@ static int input (void );
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
 #define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
 #endif
 
 /* Copy whatever the last rule matched to the standard output. */
@@ -1025,7 +1063,7 @@ static int input (void );
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
 #endif
 
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -1118,10 +1156,10 @@ YY_DECL
 	register char *yy_cp, *yy_bp;
 	register int yy_act;
     
-#line 63 "prom_lex.l"
+#line 65 "prom_lex.l"
 
 
-#line 1125 "<stdout>"
+#line 1163 "<stdout>"
 
 	if ( !(yy_init) )
 		{
@@ -1202,78 +1240,78 @@ do_action:	/* This label is used only to
 
 case 1:
 YY_RULE_SETUP
-#line 65 "prom_lex.l"
+#line 67 "prom_lex.l"
 { upval(CHOSEN); }
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 66 "prom_lex.l"
+#line 68 "prom_lex.l"
 { upval(VDEVICE); }
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 67 "prom_lex.l"
+#line 69 "prom_lex.l"
 { upval(VDEVINST); }
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 68 "prom_lex.l"
+#line 70 "prom_lex.l"
 { upval(VDEVDEV); }
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 69 "prom_lex.l"
+#line 71 "prom_lex.l"
 { upval(VDEVRAW); }
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 70 "prom_lex.l"
+#line 72 "prom_lex.l"
 { upval(OBPQUAL); }
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 71 "prom_lex.l"
+#line 73 "prom_lex.l"
 { upval(BUSNAME); }
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 72 "prom_lex.l"
+#line 74 "prom_lex.l"
 { upval(IPV4); }
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 73 "prom_lex.l"
+#line 75 "prom_lex.l"
 { upval(IQN); }
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 74 "prom_lex.l"
+#line 76 "prom_lex.l"
 { upval(BOOTDEV); }
 	YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 75 "prom_lex.l"
+#line 77 "prom_lex.l"
 { upval(OBPPARM); }
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 76 "prom_lex.l"
+#line 78 "prom_lex.l"
 { upval(HEX4); }
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 77 "prom_lex.l"
+#line 79 "prom_lex.l"
 { upval(HEX16); }
 	YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 78 "prom_lex.l"
+#line 80 "prom_lex.l"
 { upval(FILENAME); }
 	YY_BREAK
 case 15:
 /* rule 15 can match eol */
 YY_RULE_SETUP
-#line 79 "prom_lex.l"
+#line 81 "prom_lex.l"
 {                  /* eat all whitespace. */
 	yylloc.first_column = yylloc.last_column;
 	yylloc.last_column += yyleng;
@@ -1281,7 +1319,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 83 "prom_lex.l"
+#line 85 "prom_lex.l"
 {			/* any other single char. */
 	dbg("??");
 	yylloc.first_column = yylloc.last_column;
@@ -1290,15 +1328,15 @@ YY_RULE_SETUP
 }
 	YY_BREAK
 case YY_STATE_EOF(INITIAL):
-#line 90 "prom_lex.l"
+#line 92 "prom_lex.l"
 yyterminate();
 	YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 91 "prom_lex.l"
+#line 93 "prom_lex.l"
 ECHO;
 	YY_BREAK
-#line 1302 "<stdout>"
+#line 1340 "<stdout>"
 
 	case YY_END_OF_BUFFER:
 		{
@@ -1528,7 +1566,7 @@ static int yy_get_next_buffer (void)
 
 		/* Read in more data. */
 		YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-			(yy_n_chars), num_to_read );
+			(yy_n_chars), (size_t) num_to_read );
 
 		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
 		}
@@ -1552,6 +1590,14 @@ static int yy_get_next_buffer (void)
 	else
 		ret_val = EOB_ACT_CONTINUE_SCAN;
 
+	if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+		/* Extend the array by 50%, plus the number we really need. */
+		yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+		YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
+		if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+			YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+	}
+
 	(yy_n_chars) += number_to_move;
 	YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
 	YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
@@ -1618,43 +1664,6 @@ static int yy_get_next_buffer (void)
 	return yy_is_jam ? 0 : yy_current_state;
 }
 
-    static void yyunput (int c, register char * yy_bp )
-{
-	register char *yy_cp;
-    
-    yy_cp = (yy_c_buf_p);
-
-	/* undo effects of setting up yytext */
-	*yy_cp = (yy_hold_char);
-
-	if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
-		{ /* need to shift things up to make room */
-		/* +2 for EOB chars. */
-		register int number_to_move = (yy_n_chars) + 2;
-		register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
-					YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
-		register char *source =
-				&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
-
-		while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
-			*--dest = *--source;
-
-		yy_cp += (int) (dest - source);
-		yy_bp += (int) (dest - source);
-		YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
-			(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
-
-		if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
-			YY_FATAL_ERROR( "flex scanner push-back overflow" );
-		}
-
-	*--yy_cp = (char) c;
-
-	(yytext_ptr) = yy_bp;
-	(yy_hold_char) = *yy_cp;
-	(yy_c_buf_p) = yy_cp;
-}
-
 #ifndef YY_NO_INPUT
 #ifdef __cplusplus
     static int yyinput (void)
@@ -1963,7 +1972,9 @@ static void yyensure_buffer_stack (void)
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
 								(num_to_alloc * sizeof(struct yy_buffer_state*)
 								);
-		
+		if ( ! (yy_buffer_stack) )
+			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
 		memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
 				
 		(yy_buffer_stack_max) = num_to_alloc;
@@ -1981,6 +1992,8 @@ static void yyensure_buffer_stack (void)
 								((yy_buffer_stack),
 								num_to_alloc * sizeof(struct yy_buffer_state*)
 								);
+		if ( ! (yy_buffer_stack) )
+			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
 
 		/* zero only the new slots.*/
 		memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
@@ -2025,7 +2038,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * 
 
 /** Setup the input buffer state to scan a string. The next call to yylex() will
  * scan from a @e copy of @a str.
- * @param str a NUL-terminated string to scan
+ * @param yystr a NUL-terminated string to scan
  * 
  * @return the newly allocated buffer state object.
  * @note If you want to scan bytes that may contain NUL values, then use
@@ -2039,8 +2052,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst 
 
 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
  * scan from a @e copy of @a bytes.
- * @param bytes the byte buffer to scan
- * @param len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
  * 
  * @return the newly allocated buffer state object.
  */
@@ -2279,7 +2292,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 91 "prom_lex.l"
+#line 93 "prom_lex.l"
 
 
 
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/prom_lex.l open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/prom_lex.l
--- open-iscsi-2.0-872-rc4-bnx2i/utils/fwparam_ibft/prom_lex.l	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/fwparam_ibft/prom_lex.l	2011-08-14 16:48:25.000000000 -0500
@@ -43,6 +43,8 @@ void dbgprint(const char *item) { fprint
 
 %option noyywrap
 %option never-interactive
+%option nounput
+%option noinput
 
 VDEVICE     vdevice
 VDEVINST    gscsi
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/client.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/client.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/client.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/client.c	2011-08-14 16:48:25.000000000 -0500
@@ -123,8 +123,10 @@ static isns_security_t *
 __create_security_context(const char *name, const char *auth_key,
 		const char *server_key)
 {
+#ifdef WITH_SECURITY
 	isns_security_t 	*ctx;
 	isns_principal_t	*princ;
+#endif /* WITH_SECURITY */
 
 	if (!isns_config.ic_security)
 		return NULL;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/db-file.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/db-file.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/db-file.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/db-file.c	2011-08-14 16:48:25.000000000 -0500
@@ -310,7 +310,7 @@ __dbe_file_load_object(const char *filen
 
 	/* Stash away the parent's index; we resolve them later on
 	 * once we've loaded all objects */
-	obj->ie_container = (isns_object_t *) ntohl(info.db_parent);
+	obj->ie_container_idx = ntohl(info.db_parent);
 
 	isns_object_list_append(result, obj);
 
@@ -493,7 +493,7 @@ isns_dbe_file_reload(isns_db_t *db)
 	/* Resolve parent/child relationship for all nodes */
 	for (i = 0; i < db->id_objects->iol_count; ++i) {
 		isns_object_t	*obj = db->id_objects->iol_data[i];
-		uint32_t	index = (uint32_t) obj->ie_container;
+		uint32_t	index = obj->ie_container_idx;
 		isns_object_t	*parent;
 
 		if (index == 0)
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/Makefile.in open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/Makefile.in
--- open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/Makefile.in	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/Makefile.in	2011-08-14 16:48:25.000000000 -0500
@@ -32,7 +32,6 @@ LIBOBJS	= server.o \
 	  security.o \
 	  authblock.o \
 	  policy.o \
-	  pki.o \
 	  register.o \
 	  query.o \
 	  getnext.o \
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/objects.h open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/objects.h
--- open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/objects.h	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/objects.h	2011-08-14 16:48:25.000000000 -0500
@@ -83,6 +83,7 @@ struct isns_object {
 
 	isns_attr_list_t	ie_attrs;
 	isns_object_t *		ie_container;
+	uint32_t		ie_container_idx;
 	isns_object_template_t *ie_template;
 
 	isns_relation_t *	ie_relation;
diff -Naurp open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/socket.c open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/socket.c
--- open-iscsi-2.0-872-rc4-bnx2i/utils/open-isns/socket.c	2010-07-11 04:05:58.000000000 -0500
+++ open-iscsi-2.0-872-rc4-bnx2i.sync/utils/open-isns/socket.c	2011-08-14 16:48:25.000000000 -0500
@@ -562,7 +562,7 @@ void
 isns_net_stream_accept(isns_socket_t *sock)
 {
 	isns_socket_t *child;
-	size_t	optlen;
+	socklen_t optlen;
 	int	fd, passcred = 0;
 
 	fd = accept(sock->is_desc, NULL, NULL);
@@ -805,7 +805,7 @@ isns_net_stream_xmit(isns_socket_t *sock
 void
 isns_net_stream_hup(isns_socket_t *sock)
 {
-	sock->is_poll_mask &= ~POLLIN;
+	sock->is_poll_mask &= ~(POLLIN|POLLOUT);
 	/* POLLHUP while connecting means we failed */
 	if (sock->is_state == ISNS_SOCK_CONNECTING)
 		isns_net_stream_error(sock, ECONNREFUSED);