From owner-svn-src-projects@FreeBSD.ORG Thu Aug 15 19:00:37 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3D13F702; Thu, 15 Aug 2013 19:00:37 +0000 (UTC) (envelope-from mav@FreeBSD.org) 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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2A2E22325; Thu, 15 Aug 2013 19:00:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7FJ0bkB065389; Thu, 15 Aug 2013 19:00:37 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7FJ0aeN065284; Thu, 15 Aug 2013 19:00:36 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201308151900.r7FJ0aeN065284@svn.freebsd.org> From: Alexander Motin Date: Thu, 15 Aug 2013 19:00:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r254375 - in projects/camlock/sys/cam: . scsi X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 19:00:37 -0000 Author: mav Date: Thu Aug 15 19:00:36 2013 New Revision: 254375 URL: http://svnweb.freebsd.org/changeset/base/254375 Log: Introduce new per-target lock to protect list of LUNs reported by device. Modified: projects/camlock/sys/cam/cam_xpt.c projects/camlock/sys/cam/cam_xpt_internal.h projects/camlock/sys/cam/scsi/scsi_xpt.c Modified: projects/camlock/sys/cam/cam_xpt.c ============================================================================== --- projects/camlock/sys/cam/cam_xpt.c Thu Aug 15 17:44:44 2013 (r254374) +++ projects/camlock/sys/cam/cam_xpt.c Thu Aug 15 19:00:36 2013 (r254375) @@ -4526,6 +4526,7 @@ xpt_alloc_target(struct cam_eb *bus, tar target->refcount = 1; target->generation = 0; target->luns = NULL; + mtx_init(&target->luns_mtx, "CAM LUNs lock", NULL, MTX_DEF); timevalclear(&target->last_reset); /* * Hold a reference to our parent bus so it @@ -4572,6 +4573,7 @@ xpt_release_target(struct cam_et *target KASSERT(TAILQ_EMPTY(&target->ed_entries), ("destroying target, but device list is not empty")); xpt_release_bus(bus); + mtx_destroy(&target->luns_mtx); if (target->luns) free(target->luns, M_CAMXPT); free(target, M_CAMXPT); Modified: projects/camlock/sys/cam/cam_xpt_internal.h ============================================================================== --- projects/camlock/sys/cam/cam_xpt_internal.h Thu Aug 15 17:44:44 2013 (r254374) +++ projects/camlock/sys/cam/cam_xpt_internal.h Thu Aug 15 19:00:36 2013 (r254375) @@ -147,6 +147,7 @@ struct cam_et { struct timeval last_reset; u_int rpl_size; struct scsi_report_luns_data *luns; + struct mtx luns_mtx; /* Protection for luns field. */ }; /* Modified: projects/camlock/sys/cam/scsi/scsi_xpt.c ============================================================================== --- projects/camlock/sys/cam/scsi/scsi_xpt.c Thu Aug 15 17:44:44 2013 (r254374) +++ projects/camlock/sys/cam/scsi/scsi_xpt.c Thu Aug 15 19:00:36 2013 (r254375) @@ -1728,11 +1728,12 @@ probe_purge_old(struct cam_path *path, s if (path->target == NULL) { return; } - if (path->target->luns == NULL) { - path->target->luns = new; - return; - } + mtx_lock(&path->target->luns_mtx); old = path->target->luns; + path->target->luns = new; + mtx_unlock(&path->target->luns_mtx); + if (old == NULL) + return; nlun_old = scsi_4btoul(old->length) / 8; nlun_new = scsi_4btoul(new->length) / 8; @@ -1774,7 +1775,6 @@ probe_purge_old(struct cam_path *path, s } } free(old, M_CAMXPT); - path->target->luns = new; } static void @@ -2011,6 +2011,7 @@ scsi_scan_bus(struct cam_periph *periph, mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path); mtx_lock(mtx); + mtx_lock(&target->luns_mtx); if (target->luns) { uint32_t first; u_int nluns = scsi_4btoul(target->luns->length) / 8; @@ -2028,6 +2029,7 @@ scsi_scan_bus(struct cam_periph *periph, if (scan_info->lunindex[target_id] < nluns) { CAM_GET_SIMPLE_LUN(target->luns, scan_info->lunindex[target_id], lun_id); + mtx_unlock(&target->luns_mtx); next_target = 0; CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_PROBE, @@ -2035,6 +2037,7 @@ scsi_scan_bus(struct cam_periph *periph, scan_info->lunindex[target_id], lun_id)); scan_info->lunindex[target_id]++; } else { + mtx_unlock(&target->luns_mtx); /* * We're done with scanning all luns. * @@ -2053,7 +2056,9 @@ scsi_scan_bus(struct cam_periph *periph, } } } - } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) { + } else { + mtx_unlock(&target->luns_mtx); + if (request_ccb->ccb_h.status != CAM_REQ_CMP) { int phl; /* @@ -2085,7 +2090,7 @@ scsi_scan_bus(struct cam_periph *periph, if (lun_id == request_ccb->ccb_h.target_lun || lun_id > scan_info->cpi->max_lun) next_target = 1; - } else { + } else { device = request_ccb->ccb_h.path->device; @@ -2101,6 +2106,7 @@ scsi_scan_bus(struct cam_periph *periph, if (lun_id == request_ccb->ccb_h.target_lun || lun_id > scan_info->cpi->max_lun) next_target = 1; + } } /*