From owner-p4-projects@FreeBSD.ORG Sun Apr 25 07:21:45 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C0F9316A4D0; Sun, 25 Apr 2004 07:21:44 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7F52416A4CE for ; Sun, 25 Apr 2004 07:21:44 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7A2E343D2D for ; Sun, 25 Apr 2004 07:21:44 -0700 (PDT) (envelope-from scottl@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.10/8.12.10) with ESMTP id i3PELiGe064482 for ; Sun, 25 Apr 2004 07:21:44 -0700 (PDT) (envelope-from scottl@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.10/8.12.10/Submit) id i3PELhan064473 for perforce@freebsd.org; Sun, 25 Apr 2004 07:21:43 -0700 (PDT) (envelope-from scottl@freebsd.org) Date: Sun, 25 Apr 2004 07:21:43 -0700 (PDT) Message-Id: <200404251421.i3PELhan064473@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to scottl@freebsd.org using -f From: Scott Long To: Perforce Change Reviews Subject: PERFORCE change 51703 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Apr 2004 14:21:45 -0000 http://perforce.freebsd.org/chv.cgi?CH=51703 Change 51703 by scottl@scottl-junior-camlock on 2004/04/25 07:21:28 Lock the request_ccb list in the probe softc. Affected files ... .. //depot/projects/scottl-camlock/src/sys/cam/cam_probe.c#8 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/cam/cam_probe.c#8 (text+ko) ==== @@ -112,6 +112,7 @@ typedef struct { TAILQ_HEAD(, ccb_hdr) request_ccbs; + struct mtx ccb_lock; probe_action action; union ccb saved_ccb; probe_flags flags; @@ -237,7 +238,7 @@ return(CAM_REQ_CMP_ERR); } - softc = (probe_softc *)malloc(sizeof(*softc), M_TEMP, M_NOWAIT); + softc = (probe_softc *)malloc(sizeof(*softc), M_TEMP, M_NOWAIT|M_ZERO); if (softc == NULL) { printf("proberegister: Unable to probe new device. " @@ -255,6 +256,7 @@ softc->work = work; TAILQ_INIT(&softc->request_ccbs); + mtx_init(&softc->ccb_lock, "Probe requst CCB lock", NULL, MTX_DEF); TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, periph_links.tqe); softc->flags = 0; @@ -277,9 +279,10 @@ struct ccb_pathinq cpi; union ccb *ccb; probe_softc *softc; + int need_renegotiate; softc = (probe_softc *)periph->softc; - ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); + need_renegotiate = 0; xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1); cpi.ccb_h.func_code = XPT_PATH_INQ; @@ -303,12 +306,14 @@ * ensures that the device is not confused by transfer negotiation * settings left over by loader or BIOS action. */ + mtx_lock(&softc->ccb_lock); + ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0) && (ccb->ccb_h.target_lun == 0)) { softc->action = PROBE_TUR; } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) { - proberequestdefaultnegotiation(periph); + need_renegotiate = 1; softc->action = PROBE_INQUIRY; } else { softc->action = PROBE_INQUIRY; @@ -318,8 +323,14 @@ softc->flags |= PROBE_NO_ANNOUNCE; else softc->flags &= ~PROBE_NO_ANNOUNCE; + mtx_unlock(&softc->ccb_lock); + if (need_renegotiate) + proberequestdefaultnegotiation(periph); + + mtx_lock(&Giant); xpt_schedule(periph, ccb->ccb_h.pinfo.priority); + mtx_unlock(&Giant); } static void @@ -758,10 +769,14 @@ xpt_release_ccb(done_ccb); break; } + mtx_lock(&softc->ccb_lock); done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe); + mtx_unlock(&softc->ccb_lock); done_ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(done_ccb); + + /* XXX How to lock this? */ if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { cam_periph_invalidate(periph); cam_periph_release(periph); @@ -773,8 +788,12 @@ static void probecleanup(struct cam_periph *periph) { - free(((probe_softc *)(periph->softc))->work, M_TEMP); - free(periph->softc, M_TEMP); + probe_softc *softc; + + softc = (probe_softc *)periph->softc; + mtx_destroy(&softc->ccb_lock); + free(softc->work, M_TEMP); + free(softc, M_TEMP); } void @@ -854,8 +873,10 @@ probe_softc *softc; softc = (probe_softc *)old_periph->softc; + mtx_lock(&softc->ccb_lock); TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, periph_links.tqe); + mtx_unlock(&softc->ccb_lock); } else { status = cam_periph_alloc(proberegister, NULL, probecleanup, probestart, "probe",