Bug 194034 - iscsictl disconnects all targets when trying to disconnect one by nickname
Summary: iscsictl disconnects all targets when trying to disconnect one by nickname
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Edward Tomasz Napierala
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-30 09:44 UTC by Benjamin Lutz
Modified: 2014-11-15 05:55 UTC (History)
2 users (show)

See Also:
trasz: mfc-stable10+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Lutz 2014-09-30 09:44:36 UTC
When connecting to iSCSI targets, they can be given by nickname as specified in /etc/iscsi.conf. For example:

# iscsictl -L
Target name                          Target portal    State
# iscsictl -A -n monolith1-1
# iscsictl -A -n monolith1-2
# iscsictl -L
Target name                          Target portal    State
iqn.2012-10.org.example:monolith1-1  monolith1.example.org Connected: da12
iqn.2012-10.org.example:monolith1-2  monolith1.example.org Connected: da13
#

Now when trying to disconnect a single target by nickname, both are disconnected:

# iscsictl -R -n monolith1-1
# iscsictl -L
Target name                          Target portal    State
#

monolith1-2 should have remained connected!

If using the full target name with the -t parameter, iscsictl works correctly.
Comment 1 Edward Tomasz Napierala freebsd_committer 2014-10-16 09:09:59 UTC
Patch below should fix the bug you've found.

Index: sys/dev/iscsi/iscsi.c
===================================================================
--- sys/dev/iscsi/iscsi.c       (revision 273163)
+++ sys/dev/iscsi/iscsi.c       (working copy)
@@ -1752,18 +1752,16 @@ static bool
 iscsi_session_conf_matches(unsigned int id1, const struct iscsi_session_conf *c1,
     unsigned int id2, const struct iscsi_session_conf *c2)
 {
-       if (id2 == 0 && c2->isc_target[0] == '\0' &&
-           c2->isc_target_addr[0] == '\0')
-               return (true);
-       if (id2 != 0 && id2 == id1)
-               return (true);
+
+       if (id2 != 0 && id2 != id1)
+               return (false);
        if (c2->isc_target[0] != '\0' &&
-           strcmp(c1->isc_target, c2->isc_target) == 0)
-               return (true);
+           strcmp(c1->isc_target, c2->isc_target) != 0)
+               return (false);
        if (c2->isc_target_addr[0] != '\0' &&
-           strcmp(c1->isc_target_addr, c2->isc_target_addr) == 0)
-               return (true);
-       return (false);
+           strcmp(c1->isc_target_addr, c2->isc_target_addr) != 0)
+               return (false);
+       return (true);
 }
 
 static int
Comment 2 commit-hook freebsd_committer 2014-10-16 09:10:15 UTC
A commit references this bug:

Author: trasz
Date: Thu Oct 16 09:09:43 UTC 2014
New revision: 273164
URL: https://svnweb.freebsd.org/changeset/base/273164

Log:
  When removing an iSCSI session, check whether all conditions match,
  not if any of them matches.  This fixes "iscsictl -Rn" removing
  unrelated sessions.

  PR:		194034
  MFC after:	1 month
  Sponsored by:	The FreeBSD Foundation

Changes:
  head/sys/dev/iscsi/iscsi.c
Comment 3 commit-hook freebsd_committer 2014-11-15 05:50:21 UTC
A commit references this bug:

Author: trasz
Date: Sat Nov 15 05:50:14 UTC 2014
New revision: 274546
URL: https://svnweb.freebsd.org/changeset/base/274546

Log:
  MFC r273164:

  When removing an iSCSI session, check whether all conditions match,
  not if any of them matches.  This fixes "iscsictl -Rn" removing
  unrelated sessions.

  PR:		194034
  Sponsored by:	The FreeBSD Foundation

Changes:
_U  stable/10/
  stable/10/sys/dev/iscsi/iscsi.c