Date: Sat, 10 Mar 2018 14:21:37 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330740 - head/sys/dev/iscsi Message-ID: <201803101421.w2AELbPO039089@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803101421.w2AELbPO039089>