From owner-p4-projects@FreeBSD.ORG Thu May 18 14:49:07 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 35D8616A407; Thu, 18 May 2006 14:49:07 +0000 (UTC) X-Original-To: perforce@freebsd.org 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 EC20B16A402 for ; Thu, 18 May 2006 14:49:06 +0000 (UTC) (envelope-from scottl@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id AF56243D45 for ; Thu, 18 May 2006 14:49:06 +0000 (GMT) (envelope-from scottl@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k4IEmfTX071264 for ; Thu, 18 May 2006 14:48:41 GMT (envelope-from scottl@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k4IEmfIw071261 for perforce@freebsd.org; Thu, 18 May 2006 14:48:41 GMT (envelope-from scottl@freebsd.org) Date: Thu, 18 May 2006 14:48:41 GMT Message-Id: <200605181448.k4IEmfIw071261@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 Cc: Subject: PERFORCE change 97407 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 May 2006 14:49:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=97407 Change 97407 by scottl@scottl-x64 on 2006/05/18 14:48:08 Introduce the xpt_lock and protect the fields in the xpt_softc with it. Affected files ... .. //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#32 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#32 (text+ko) ==== @@ -249,6 +249,8 @@ u_int bus_generation; struct intr_config_hook *xpt_config_hook; + + struct mtx xpt_lock; }; static const char quantum[] = "QUANTUM"; @@ -1375,6 +1377,7 @@ xsoftc.num_highpower = CAM_MAX_HIGHPOWER; mtx_init(&cam_bioq_lock, "CAM BIOQ lock", NULL, MTX_DEF); + mtx_init(&xsoftc.xpt_lock, "XPT lock", NULL, MTX_DEF); /* * The xpt layer is, itself, the equivelent of a SIM. @@ -1488,7 +1491,7 @@ splx(s); } - xsoftc.xpt_generation++; + atomic_add_int(&xsoftc.xpt_generation, 1); return (status); } @@ -1519,7 +1522,7 @@ splx(s); } - xsoftc.xpt_generation++; + atomic_add_int(&xsoftc.xpt_generation, 1); } @@ -2637,15 +2640,19 @@ retval = 1; + mtx_lock(&xsoftc.xpt_lock); for (bus = (start_bus ? start_bus : TAILQ_FIRST(&xsoftc.xpt_busses)); bus != NULL; bus = next_bus) { next_bus = TAILQ_NEXT(bus, links); + mtx_unlock(&xsoftc.xpt_lock); retval = tr_func(bus, arg); if (retval == 0) return(retval); + mtx_lock(&xsoftc.xpt_lock); } + mtx_unlock(&xsoftc.xpt_lock); return(retval); } @@ -3895,6 +3902,7 @@ if ((work_ccb->ccb_h.flags & CAM_HIGH_POWER) != 0) { + mtx_lock(&xsoftc.xpt_lock); if (xsoftc.num_highpower <= 0) { /* * We got a high power command, but we @@ -3916,6 +3924,7 @@ */ xsoftc.num_highpower--; } + mtx_unlock(&xsoftc.xpt_lock); } devq->active_dev = device; cam_ccbq_remove_ccb(&device->ccbq, work_ccb); @@ -4394,6 +4403,7 @@ new_bus->refcount = 1; /* Held until a bus_deregister event */ new_bus->generation = 0; s = splcam(); + mtx_lock(&xsoftc.xpt_lock); old_bus = TAILQ_FIRST(&xsoftc.xpt_busses); while (old_bus != NULL && old_bus->path_id < new_bus->path_id) @@ -4403,6 +4413,7 @@ else TAILQ_INSERT_TAIL(&xsoftc.xpt_busses, new_bus, links); xsoftc.bus_generation++; + mtx_unlock(&xsoftc.xpt_lock); splx(s); /* Notify interested parties */ @@ -4497,6 +4508,7 @@ const char *strval; pathid = 0; + mtx_lock(&xsoftc.xpt_lock); bus = TAILQ_FIRST(&xsoftc.xpt_busses); retry: /* Find an unoccupied pathid */ @@ -4506,6 +4518,7 @@ pathid++; bus = TAILQ_NEXT(bus, links); } + mtx_unlock(&xsoftc.xpt_lock); /* * Ensure that this pathid is not reserved for @@ -4514,6 +4527,7 @@ if (resource_string_value("scbus", pathid, "at", &strval) == 0) { ++pathid; /* Start the search over */ + mtx_lock(&xsoftc.xpt_lock); goto retry; } return (pathid); @@ -4999,8 +5013,10 @@ s = splcam(); if ((--bus->refcount == 0) && (TAILQ_FIRST(&bus->et_entries) == NULL)) { + mtx_lock(&xsoftc.xpt_lock); TAILQ_REMOVE(&xsoftc.xpt_busses, bus, links); xsoftc.bus_generation++; + mtx_unlock(&xsoftc.xpt_lock); splx(s); free(bus, M_CAMXPT); } else @@ -5230,6 +5246,7 @@ { struct cam_eb *bus; + mtx_lock(&xsoftc.xpt_lock); for (bus = TAILQ_FIRST(&xsoftc.xpt_busses); bus != NULL; bus = TAILQ_NEXT(bus, links)) { @@ -5238,6 +5255,7 @@ break; } } + mtx_unlock(&xsoftc.xpt_lock); return (bus); } @@ -7125,6 +7143,7 @@ struct highpowerlist *hphead; union ccb *send_ccb; + mtx_lock(&xsoftc.xpt_lock); hphead = &xsoftc.highpowerq; send_ccb = (union ccb *)STAILQ_FIRST(hphead); @@ -7133,6 +7152,7 @@ * Increment the count since this command is done. */ xsoftc.num_highpower++; + mtx_unlock(&xsoftc.xpt_lock); /* * Any high powered commands queued up?