From owner-svn-src-head@freebsd.org Fri Sep 25 22:45:24 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2C20BA091F4; Fri, 25 Sep 2015 22:45:24 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 03F431FD1; Fri, 25 Sep 2015 22:45:24 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8PMjNZx090564; Fri, 25 Sep 2015 22:45:23 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8PMjNZJ090563; Fri, 25 Sep 2015 22:45:23 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201509252245.t8PMjNZJ090563@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Fri, 25 Sep 2015 22:45:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288239 - head/sys/cam/ctl X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Sep 2015 22:45:24 -0000 Author: mav Date: Fri Sep 25 22:45:23 2015 New Revision: 288239 URL: https://svnweb.freebsd.org/changeset/base/288239 Log: Properly lock LUN in ctl_failover_lun(). Modified: head/sys/cam/ctl/ctl.c Modified: head/sys/cam/ctl/ctl.c ============================================================================== --- head/sys/cam/ctl/ctl.c Fri Sep 25 22:29:21 2015 (r288238) +++ head/sys/cam/ctl/ctl.c Fri Sep 25 22:45:23 2015 (r288239) @@ -424,7 +424,7 @@ static int ctl_check_blocked(struct ctl_ static int ctl_scsiio_lun_check(struct ctl_lun *lun, const struct ctl_cmd_entry *entry, struct ctl_scsiio *ctsio); -static void ctl_failover_lun(struct ctl_lun *lun); +static void ctl_failover_lun(union ctl_io *io); static int ctl_scsiio_precheck(struct ctl_softc *ctl_softc, struct ctl_scsiio *ctsio); static int ctl_scsiio(struct ctl_scsiio *ctsio); @@ -11199,12 +11199,31 @@ ctl_failover_io(union ctl_io *io, int ha } static void -ctl_failover_lun(struct ctl_lun *lun) +ctl_failover_lun(union ctl_io *rio) { - struct ctl_softc *softc = lun->ctl_softc; + struct ctl_softc *softc = control_softc; + struct ctl_lun *lun; struct ctl_io_hdr *io, *next_io; + uint32_t targ_lun; + + targ_lun = rio->io_hdr.nexus.targ_mapped_lun; + CTL_DEBUG_PRINT(("FAILOVER for lun %ju\n", targ_lun)); + + /* Find and lock the LUN. */ + mtx_lock(&softc->ctl_lock); + if ((targ_lun < CTL_MAX_LUNS) && + ((lun = softc->ctl_luns[targ_lun]) != NULL)) { + mtx_lock(&lun->lun_lock); + mtx_unlock(&softc->ctl_lock); + if (lun->flags & CTL_LUN_DISABLED) { + mtx_unlock(&lun->lun_lock); + return; + } + } else { + mtx_unlock(&softc->ctl_lock); + return; + } - CTL_DEBUG_PRINT(("FAILOVER for lun %ju\n", lun->lun)); if (softc->ha_mode == CTL_HA_MODE_XFER) { TAILQ_FOREACH_SAFE(io, &lun->ooa_queue, ooa_links, next_io) { /* We are master */ @@ -11262,6 +11281,7 @@ ctl_failover_lun(struct ctl_lun *lun) } ctl_check_blocked(lun); } + mtx_unlock(&lun->lun_lock); } static int @@ -12194,9 +12214,7 @@ ctl_handle_isc(union ctl_io *io) io->scsiio.be_move_done(io); break; case CTL_MSG_FAILOVER: - mtx_lock(&lun->lun_lock); - ctl_failover_lun(lun); - mtx_unlock(&lun->lun_lock); + ctl_failover_lun(io); free_io = 1; break; default: