aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/cam_sim.c
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2008-12-16 16:57:33 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2008-12-16 16:57:33 +0000
commitfa6099fda0f4866ce085895d4a552f9fa9a7c8f8 (patch)
tree4b0fd6e2cd5eb30999a8168d4c935eca7d284ac6 /sys/cam/cam_sim.c
parent96100101a8588d9f61eb13a843fb1a9574c49bdd (diff)
downloadsrc-fa6099fda0f4866ce085895d4a552f9fa9a7c8f8.tar.gz
src-fa6099fda0f4866ce085895d4a552f9fa9a7c8f8.zip
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
Notes
Notes: svn path=/head/; revision=186185
Diffstat (limited to 'sys/cam/cam_sim.c')
-rw-r--r--sys/cam/cam_sim.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/sys/cam/cam_sim.c b/sys/cam/cam_sim.c
index cfc20447c224..d7fcaad1afa7 100644
--- a/sys/cam/cam_sim.c
+++ b/sys/cam/cam_sim.c
@@ -84,6 +84,7 @@ cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll,
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, sim_poll_func sim_poll,
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;