From owner-p4-projects@FreeBSD.ORG Fri May 19 07:12:02 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 600E916A428; Fri, 19 May 2006 07:12:02 +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 0B33716A420 for ; Fri, 19 May 2006 07:12:02 +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 BAFFD43D46 for ; Fri, 19 May 2006 07:12:01 +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 k4J7BXAa073010 for ; Fri, 19 May 2006 07:11:33 GMT (envelope-from scottl@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k4J7BXcV073007 for perforce@freebsd.org; Fri, 19 May 2006 07:11:33 GMT (envelope-from scottl@freebsd.org) Date: Fri, 19 May 2006 07:11:33 GMT Message-Id: <200605190711.k4J7BXcV073007@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 97448 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: Fri, 19 May 2006 07:12:02 -0000 http://perforce.freebsd.org/chv.cgi?CH=97448 Change 97448 by scottl@scottl-x64 on 2006/05/19 07:10:54 Mark the xpt cdevsw as MPSAFE. Add appropriate locking to the associated device entry points. xpt_find_bus() turns out to be incredibly convenient for making xptioctl work. Affected files ... .. //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#33 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#33 (text+ko) ==== @@ -83,6 +83,9 @@ SLIST_HEAD(async_list, async_node); SLIST_HEAD(periph_list, cam_periph); +#define CAM_SIM_LOCK(sim) mtx_lock((sim)->mtx); +#define CAM_SIM_UNLOCK(sim) mtx_unlock((sim)->mtx); + /* * This is the maximum number of high powered commands (e.g. start unit) * that can be outstanding at a particular time. @@ -676,7 +679,7 @@ static struct cdevsw xpt_cdevsw = { .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, + .d_flags = 0, .d_open = xptopen, .d_close = xptclose, .d_ioctl = xptioctl, @@ -997,7 +1000,9 @@ } /* Mark ourselves open */ + mtx_lock(&xsoftc.xpt_lock); xsoftc.flags |= XPT_FLAG_OPEN; + mtx_unlock(&xsoftc.xpt_lock); return(0); } @@ -1007,7 +1012,9 @@ { /* Mark ourselves closed */ + mtx_lock(&xsoftc.xpt_lock); xsoftc.flags &= ~XPT_FLAG_OPEN; + mtx_unlock(&xsoftc.xpt_lock); return(0); } @@ -1029,9 +1036,16 @@ case CAMIOCOMMAND: { union ccb *ccb; union ccb *inccb; + struct cam_eb *bus; inccb = (union ccb *)addr; + bus = xpt_find_bus(inccb->ccb_h.path_id); + if (bus == NULL) { + error = EINVAL; + break; + } + switch(inccb->ccb_h.func_code) { case XPT_SCAN_BUS: case XPT_RESET_BUS: @@ -1047,6 +1061,8 @@ ccb = xpt_alloc_ccb(); + CAM_SIM_LOCK(bus->sim); + /* * Create a path using the bus, target, and lun the * user passed in. @@ -1057,6 +1073,7 @@ inccb->ccb_h.target_lun) != CAM_REQ_CMP){ error = EINVAL; + CAM_SIM_UNLOCK(bus->sim); xpt_free_ccb(ccb); break; } @@ -1066,6 +1083,7 @@ xpt_merge_ccb(ccb, inccb); ccb->ccb_h.cbfcnp = xptdone; cam_periph_runccb(ccb, NULL, 0, 0, NULL); + CAM_SIM_UNLOCK(bus->sim); bcopy(ccb, inccb, sizeof(union ccb)); xpt_free_path(ccb->ccb_h.path); xpt_free_ccb(ccb); @@ -1079,6 +1097,8 @@ * allocate it on the stack. */ + CAM_SIM_LOCK(bus->sim); + /* * Create a path using the bus, target, and lun the * user passed in. @@ -1097,6 +1117,7 @@ xpt_merge_ccb(&ccb, inccb); ccb.ccb_h.cbfcnp = xptdone; xpt_action(&ccb); + CAM_SIM_UNLOCK(bus->sim); bcopy(&ccb, inccb, sizeof(union ccb)); xpt_free_path(ccb.ccb_h.path); break; @@ -1145,7 +1166,9 @@ /* * This is an immediate CCB, we can send it on directly. */ + CAM_SIM_LOCK(bus->sim); xpt_action(inccb); + CAM_SIM_UNLOCK(bus->sim); /* * Map the buffers back into user space. @@ -1452,6 +1475,7 @@ xpt_sim = (struct cam_sim *)arg; xpt_sim->softc = periph; + xpt_periph = periph; periph->softc = NULL; return(CAM_REQ_CMP);