Messages in this thread Patch in this message | | | Date | Thu, 13 Apr 2006 16:35:46 -0400 | From | Jeff Mahoney <> | Subject | [PATCH 04/08] dm: use spinlock for _minor_lock |
| |
In order to truly serialize reference counting and properly handle the final dm_put, we need to use atomic_dec_and_lock, since another thread of execution can attempt to "resurrect" a potentially dead mapped_device.
This patch replaces the _minor_lock mutex with a spinlock, and leverages atomic_dec_and_lock to properly serialize reference counting.
Signed-off-by: Jeff Mahoney <jeffm@suse.com> -- drivers/md/dm.c | 27 +++++++++++++-------------- 1 files changed, 13 insertions(+), 14 deletions(-)
diff -ruNpX ../dontdiff linux-2.6.16-staging1/drivers/md/dm.c linux-2.6.16-staging2/drivers/md/dm.c --- linux-2.6.16-staging1/drivers/md/dm.c 2006-04-13 16:18:19.000000000 -0400 +++ linux-2.6.16-staging2/drivers/md/dm.c 2006-04-13 16:18:19.000000000 -0400 @@ -23,6 +23,7 @@ static const char *_name = DM_NAME; static unsigned int major = 0; static unsigned int _major = 0; +static DEFINE_SPINLOCK(_minor_lock); /* * One of these is allocated per bio. */ @@ -697,14 +698,13 @@ static int dm_any_congested(void *conges /*----------------------------------------------------------------- * An IDR is used to keep track of allocated minor numbers. *---------------------------------------------------------------*/ -static DECLARE_MUTEX(_minor_lock); static DEFINE_IDR(_minor_idr); static void free_minor(unsigned int minor) { - down(&_minor_lock); + spin_lock(&_minor_lock); idr_remove(&_minor_idr, minor); - up(&_minor_lock); + spin_unlock(&_minor_lock); } /* @@ -721,7 +721,7 @@ static int specific_minor(struct mapped_ if (!r) return -ENOMEM; - down(&_minor_lock); + spin_lock(&_minor_lock); if (idr_find(&_minor_idr, minor)) { r = -EBUSY; @@ -740,7 +740,7 @@ static int specific_minor(struct mapped_ } out: - up(&_minor_lock); + spin_unlock(&_minor_lock); return r; } @@ -753,7 +753,7 @@ static int next_free_minor(struct mapped if (!r) return -ENOMEM; - down(&_minor_lock); + spin_lock(&_minor_lock); r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m); if (r) { @@ -769,7 +769,7 @@ static int next_free_minor(struct mapped *minor = m; out: - up(&_minor_lock); + spin_unlock(&_minor_lock); return r; } @@ -839,9 +839,9 @@ static struct mapped_device *alloc_dev(u init_waitqueue_head(&md->eventq); /* Populate the mapping, nobody knows we exist yet */ - down(&_minor_lock); + spin_lock(&_minor_lock); r = idr_replace(&_minor_idr, md, minor); - up(&_minor_lock); + spin_unlock(&_minor_lock); BUG_ON(r < 0); return md; @@ -964,13 +964,13 @@ static struct mapped_device *dm_find_md( if (MAJOR(dev) != _major || minor >= (1 << MINORBITS)) return NULL; - down(&_minor_lock); + spin_lock(&_minor_lock); md = idr_find(&_minor_idr, minor); if (md && (md == MINOR_ALLOCED || (dm_disk(md)->first_minor != minor))) md = NULL; - up(&_minor_lock); + spin_unlock(&_minor_lock); return md; } @@ -1010,10 +1010,9 @@ void dm_put(struct mapped_device *md) { struct dm_table *map = dm_get_table(md); - if (atomic_dec_and_test(&md->holders)) { - down(&_minor_lock); + if (atomic_dec_and_lock(&md->holders, &_minor_lock)) { idr_replace(&_minor_idr, MINOR_ALLOCED, md->disk->first_minor); - up(&_minor_lock); + spin_unlock(&_minor_lock); if (!dm_suspended(md)) { dm_table_presuspend_targets(map); dm_table_postsuspend_targets(map); - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |