From owner-svn-src-all@FreeBSD.ORG Mon Sep 22 07:59:26 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B5B7A3C8; Mon, 22 Sep 2014 07:59:26 +0000 (UTC) Received: from svn.freebsd.org (svn.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 95317C9B; Mon, 22 Sep 2014 07:59:26 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8M7xQxG017320; Mon, 22 Sep 2014 07:59:26 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8M7xQZl017317; Mon, 22 Sep 2014 07:59:26 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201409220759.s8M7xQZl017317@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 22 Sep 2014 07:59:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271945 - 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-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Sep 2014 07:59:26 -0000 Author: mav Date: Mon Sep 22 07:59:25 2014 New Revision: 271945 URL: http://svnweb.freebsd.org/changeset/base/271945 Log: Simplify legacy reservation handling. Drop it on I_T nexus loss. Modified: head/sys/cam/ctl/ctl.c head/sys/cam/ctl/ctl_private.h Modified: head/sys/cam/ctl/ctl.c ============================================================================== --- head/sys/cam/ctl/ctl.c Mon Sep 22 05:07:22 2014 (r271944) +++ head/sys/cam/ctl/ctl.c Mon Sep 22 07:59:25 2014 (r271945) @@ -5308,12 +5308,14 @@ ctl_scsi_release(struct ctl_scsiio *ctsi int length, longid, thirdparty_id, resv_id; struct ctl_softc *ctl_softc; struct ctl_lun *lun; + uint32_t residx; length = 0; resv_id = 0; CTL_DEBUG_PRINT(("ctl_scsi_release\n")); + residx = ctl_get_resindex(&ctsio->io_hdr.nexus); lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; ctl_softc = control_softc; @@ -5371,14 +5373,8 @@ ctl_scsi_release(struct ctl_scsiio *ctsi * released, though, by the initiator who made it or by one of * several reset type events. */ - if (lun->flags & CTL_LUN_RESERVED) { - if ((ctsio->io_hdr.nexus.initid.id == lun->rsv_nexus.initid.id) - && (ctsio->io_hdr.nexus.targ_port == lun->rsv_nexus.targ_port) - && (ctsio->io_hdr.nexus.targ_target.id == - lun->rsv_nexus.targ_target.id)) { + if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx == residx)) lun->flags &= ~CTL_LUN_RESERVED; - } - } mtx_unlock(&lun->lun_lock); @@ -5402,6 +5398,7 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsi uint64_t thirdparty_id; struct ctl_softc *ctl_softc; struct ctl_lun *lun; + uint32_t residx; extent = 0; thirdparty = 0; @@ -5412,6 +5409,7 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsi CTL_DEBUG_PRINT(("ctl_reserve\n")); + residx = ctl_get_resindex(&ctsio->io_hdr.nexus); lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; ctl_softc = control_softc; @@ -5460,19 +5458,14 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsi thirdparty_id = scsi_8btou64(ctsio->kern_data_ptr); mtx_lock(&lun->lun_lock); - if (lun->flags & CTL_LUN_RESERVED) { - if ((ctsio->io_hdr.nexus.initid.id != lun->rsv_nexus.initid.id) - || (ctsio->io_hdr.nexus.targ_port != lun->rsv_nexus.targ_port) - || (ctsio->io_hdr.nexus.targ_target.id != - lun->rsv_nexus.targ_target.id)) { - ctsio->scsi_status = SCSI_STATUS_RESERV_CONFLICT; - ctsio->io_hdr.status = CTL_SCSI_ERROR; - goto bailout; - } + if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx != residx)) { + ctsio->scsi_status = SCSI_STATUS_RESERV_CONFLICT; + ctsio->io_hdr.status = CTL_SCSI_ERROR; + goto bailout; } lun->flags |= CTL_LUN_RESERVED; - lun->rsv_nexus = ctsio->io_hdr.nexus; + lun->res_idx = residx; ctsio->scsi_status = SCSI_STATUS_OK; ctsio->io_hdr.status = CTL_SUCCESS; @@ -11260,6 +11253,7 @@ ctl_scsiio_lun_check(struct ctl_softc *c const struct ctl_cmd_entry *entry, struct ctl_scsiio *ctsio) { int retval; + uint32_t residx; retval = 0; @@ -11284,12 +11278,10 @@ ctl_scsiio_lun_check(struct ctl_softc *c * even on reserved LUNs, and if this initiator isn't the one who * reserved us, reject the command with a reservation conflict. */ + residx = ctl_get_resindex(&ctsio->io_hdr.nexus); if ((lun->flags & CTL_LUN_RESERVED) && ((entry->flags & CTL_CMD_FLAG_ALLOW_ON_RESV) == 0)) { - if ((ctsio->io_hdr.nexus.initid.id != lun->rsv_nexus.initid.id) - || (ctsio->io_hdr.nexus.targ_port != lun->rsv_nexus.targ_port) - || (ctsio->io_hdr.nexus.targ_target.id != - lun->rsv_nexus.targ_target.id)) { + if (lun->res_idx != residx) { ctsio->scsi_status = SCSI_STATUS_RESERV_CONFLICT; ctsio->io_hdr.status = CTL_SCSI_ERROR; retval = 1; @@ -11297,11 +11289,8 @@ ctl_scsiio_lun_check(struct ctl_softc *c } } - if ( (lun->flags & CTL_LUN_PR_RESERVED) + if ((lun->flags & CTL_LUN_PR_RESERVED) && ((entry->flags & CTL_CMD_FLAG_ALLOW_ON_PR_RESV) == 0)) { - uint32_t residx; - - residx = ctl_get_resindex(&ctsio->io_hdr.nexus); /* * if we aren't registered or it's a res holder type * reservation and this isn't the res holder then set a @@ -12167,9 +12156,10 @@ ctl_i_t_nexus_reset(union ctl_io *io) { struct ctl_softc *softc = control_softc; struct ctl_lun *lun; - uint32_t initindex; + uint32_t initindex, residx; initindex = ctl_get_initindex(&io->io_hdr.nexus); + residx = ctl_get_resindex(&io->io_hdr.nexus); mtx_lock(&softc->ctl_lock); STAILQ_FOREACH(lun, &softc->lun_list, links) { mtx_lock(&lun->lun_lock); @@ -12179,6 +12169,8 @@ ctl_i_t_nexus_reset(union ctl_io *io) #ifdef CTL_WITH_CA ctl_clear_mask(lun->have_ca, initindex); #endif + if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx == residx)) + lun->flags &= ~CTL_LUN_RESERVED; lun->pending_ua[initindex] |= CTL_UA_I_T_NEXUS_LOSS; mtx_unlock(&lun->lun_lock); } Modified: head/sys/cam/ctl/ctl_private.h ============================================================================== --- head/sys/cam/ctl/ctl_private.h Mon Sep 22 05:07:22 2014 (r271944) +++ head/sys/cam/ctl/ctl_private.h Mon Sep 22 07:59:25 2014 (r271945) @@ -389,7 +389,6 @@ struct ctl_lun { TAILQ_HEAD(ctl_blockq,ctl_io_hdr) blocked_queue; STAILQ_ENTRY(ctl_lun) links; STAILQ_ENTRY(ctl_lun) run_links; - struct ctl_nexus rsv_nexus; #ifdef CTL_WITH_CA uint32_t have_ca[CTL_MAX_INITIATORS >> 5]; struct scsi_sense_data pending_sense[CTL_MAX_INITIATORS]; @@ -397,6 +396,7 @@ struct ctl_lun { ctl_ua_type pending_ua[CTL_MAX_INITIATORS]; struct ctl_mode_pages mode_pages; struct ctl_lun_io_stats stats; + uint32_t res_idx; struct ctl_per_res_info per_res[2*CTL_MAX_INITIATORS]; unsigned int PRGeneration; int pr_key_count;