svn commit: r330740 - head/sys/dev/iscsi
Edward Tomasz Napierala
trasz at FreeBSD.org
Sat Mar 10 14:21:38 UTC 2018
Author: trasz
Date: Sat Mar 10 14:21:37 2018
New Revision: 330740
URL: https://svnweb.freebsd.org/changeset/base/330740
Log:
Check for duplicates when modifying an iSCSI session. Previously we did
this check on open, but "iscsictl -M", or an iSCSI redirect received by
iscsid(8) could end up with two sessions with the same target name and
portal.
MFC after: 2 weeks
Modified:
head/sys/dev/iscsi/iscsi.c
Modified: head/sys/dev/iscsi/iscsi.c
==============================================================================
--- head/sys/dev/iscsi/iscsi.c Sat Mar 10 09:17:52 2018 (r330739)
+++ head/sys/dev/iscsi/iscsi.c Sat Mar 10 14:21:37 2018 (r330740)
@@ -1983,6 +1983,7 @@ iscsi_ioctl_session_modify(struct iscsi_softc *sc,
struct iscsi_session_modify *ism)
{
struct iscsi_session *is;
+ const struct iscsi_session *is2;
iscsi_sanitize_session_conf(&ism->ism_conf);
if (iscsi_valid_session_conf(&ism->ism_conf) == false)
@@ -1991,14 +1992,42 @@ iscsi_ioctl_session_modify(struct iscsi_softc *sc,
sx_xlock(&sc->sc_lock);
TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
ISCSI_SESSION_LOCK(is);
- if (is->is_id == ism->ism_session_id)
+ if (is->is_id == ism->ism_session_id) {
+ /* Note that the session remains locked. */
break;
+ }
ISCSI_SESSION_UNLOCK(is);
}
if (is == NULL) {
sx_xunlock(&sc->sc_lock);
return (ESRCH);
}
+
+ /*
+ * Prevent duplicates.
+ */
+ TAILQ_FOREACH(is2, &sc->sc_sessions, is_next) {
+ if (is == is2)
+ continue;
+
+ if (!!ism->ism_conf.isc_discovery !=
+ !!is2->is_conf.isc_discovery)
+ continue;
+
+ if (strcmp(ism->ism_conf.isc_target_addr,
+ is2->is_conf.isc_target_addr) != 0)
+ continue;
+
+ if (ism->ism_conf.isc_discovery == 0 &&
+ strcmp(ism->ism_conf.isc_target,
+ is2->is_conf.isc_target) != 0)
+ continue;
+
+ ISCSI_SESSION_UNLOCK(is);
+ sx_xunlock(&sc->sc_lock);
+ return (EBUSY);
+ }
+
sx_xunlock(&sc->sc_lock);
memcpy(&is->is_conf, &ism->ism_conf, sizeof(is->is_conf));
More information about the svn-src-head
mailing list