From owner-svn-src-stable@FreeBSD.ORG Sat Feb 28 10:27:47 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 001DC106566B; Sat, 28 Feb 2009 10:27:46 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E1A918FC14; Sat, 28 Feb 2009 10:27:46 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1SARk8C002616; Sat, 28 Feb 2009 10:27:46 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1SARkDb002613; Sat, 28 Feb 2009 10:27:46 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <200902281027.n1SARkDb002613@svn.freebsd.org> From: Edward Tomasz Napierala Date: Sat, 28 Feb 2009 10:27:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189145 - in stable/7/sys: . cam contrib/pf dev/cxgb X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Feb 2009 10:27:47 -0000 Author: trasz Date: Sat Feb 28 10:27:46 2009 New Revision: 189145 URL: http://svn.freebsd.org/changeset/base/189145 Log: MFC r186185: Add SIM refcounting. This is slightly different from what DragonFly does - in DragonFly, it's cam_sim_release() what actually frees the SIM; cam_sim_free does nothing more than calling cam_sim_release(). Here, we drain in cam_sim_free, waiting for refcount to drop to zero. We cannot do the same think DragonFly does, because after cam_sim_free returns, client would destroy the sim->mtx, and CAM would trip over an initialized mutex. Reviewed by: scottl Approved by: rwatson (mentor) Sponsored by: FreeBSD Foundation Modified: stable/7/sys/ (props changed) stable/7/sys/cam/cam_sim.c stable/7/sys/cam/cam_sim.h stable/7/sys/cam/cam_xpt.c stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/cxgb/ (props changed) Modified: stable/7/sys/cam/cam_sim.c ============================================================================== --- stable/7/sys/cam/cam_sim.c Sat Feb 28 10:24:57 2009 (r189144) +++ stable/7/sys/cam/cam_sim.c Sat Feb 28 10:27:46 2009 (r189145) @@ -84,6 +84,7 @@ cam_sim_alloc(sim_action_func sim_action sim->max_tagged_dev_openings = max_tagged_dev_transactions; sim->max_dev_openings = max_dev_transactions; sim->flags = 0; + sim->refcount = 1; sim->devq = queue; sim->mtx = mtx; if (mtx == &Giant) { @@ -103,12 +104,40 @@ cam_sim_alloc(sim_action_func sim_action void cam_sim_free(struct cam_sim *sim, int free_devq) { + int error; + + sim->refcount--; + if (sim->refcount > 0) { + error = msleep(sim, sim->mtx, PRIBIO, "simfree", 0); + KASSERT(error == 0, ("invalid error value for msleep(9)")); + } + + KASSERT(sim->refcount == 0, ("sim->refcount == 0")); + if (free_devq) cam_simq_free(sim->devq); free(sim, M_CAMSIM); } void +cam_sim_release(struct cam_sim *sim) +{ + KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); + + sim->refcount--; + if (sim->refcount <= 1) + wakeup(sim); +} + +void +cam_sim_hold(struct cam_sim *sim) +{ + KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); + + sim->refcount++; +} + +void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id) { sim->path_id = path_id; Modified: stable/7/sys/cam/cam_sim.h ============================================================================== --- stable/7/sys/cam/cam_sim.h Sat Feb 28 10:24:57 2009 (r189144) +++ stable/7/sys/cam/cam_sim.h Sat Feb 28 10:27:46 2009 (r189145) @@ -61,6 +61,8 @@ struct cam_sim * cam_sim_alloc(sim_acti int max_tagged_dev_transactions, struct cam_devq *queue); void cam_sim_free(struct cam_sim *sim, int free_devq); +void cam_sim_hold(struct cam_sim *sim); +void cam_sim_release(struct cam_sim *sim); /* Optional sim attributes may be set with these. */ void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id); @@ -105,6 +107,7 @@ struct cam_sim { #define CAM_SIM_ON_DONEQ 0x04 struct callout callout; struct cam_devq *devq; /* Device Queue to use for this SIM */ + int refcount; /* References to the SIM. */ /* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */ SLIST_HEAD(,ccb_hdr) ccb_freeq; Modified: stable/7/sys/cam/cam_xpt.c ============================================================================== --- stable/7/sys/cam/cam_xpt.c Sat Feb 28 10:24:57 2009 (r189144) +++ stable/7/sys/cam/cam_xpt.c Sat Feb 28 10:27:46 2009 (r189145) @@ -4304,6 +4304,7 @@ xpt_bus_register(struct cam_sim *sim, de TAILQ_INIT(&new_bus->et_entries); new_bus->path_id = sim->path_id; + cam_sim_hold(sim); new_bus->sim = sim; timevalclear(&new_bus->last_reset); new_bus->flags = 0; @@ -4846,6 +4847,7 @@ xpt_release_bus(struct cam_eb *bus) TAILQ_REMOVE(&xsoftc.xpt_busses, bus, links); xsoftc.bus_generation++; mtx_unlock(&xsoftc.xpt_topo_lock); + cam_sim_release(bus->sim); free(bus, M_CAMXPT); } }