Commit f32c10b0 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Linus Torvalds

[PATCH] dm: change minor_lock to spinlock

While removing a device, another another thread might attempt to resurrect it.

This patch replaces the _minor_lock mutex with a spinlock and uses
atomic_dec_and_lock() to serialize reference counting in dm_put().

[akpm: too late for 2.6.17 - suitable for 2.6.17.x after it has settled]
Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
Cc: <stable@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 62f75c2f
...@@ -26,6 +26,7 @@ static const char *_name = DM_NAME; ...@@ -26,6 +26,7 @@ static const char *_name = DM_NAME;
static unsigned int major = 0; static unsigned int major = 0;
static unsigned int _major = 0; static unsigned int _major = 0;
static DEFINE_SPINLOCK(_minor_lock);
/* /*
* One of these is allocated per bio. * One of these is allocated per bio.
*/ */
...@@ -746,14 +747,13 @@ static int dm_any_congested(void *congested_data, int bdi_bits) ...@@ -746,14 +747,13 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* An IDR is used to keep track of allocated minor numbers. * An IDR is used to keep track of allocated minor numbers.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
static DEFINE_MUTEX(_minor_lock);
static DEFINE_IDR(_minor_idr); static DEFINE_IDR(_minor_idr);
static void free_minor(unsigned int minor) static void free_minor(unsigned int minor)
{ {
mutex_lock(&_minor_lock); spin_lock(&_minor_lock);
idr_remove(&_minor_idr, minor); idr_remove(&_minor_idr, minor);
mutex_unlock(&_minor_lock); spin_unlock(&_minor_lock);
} }
/* /*
...@@ -770,7 +770,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor) ...@@ -770,7 +770,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor)
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
mutex_lock(&_minor_lock); spin_lock(&_minor_lock);
if (idr_find(&_minor_idr, minor)) { if (idr_find(&_minor_idr, minor)) {
r = -EBUSY; r = -EBUSY;
...@@ -788,7 +788,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor) ...@@ -788,7 +788,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor)
} }
out: out:
mutex_unlock(&_minor_lock); spin_unlock(&_minor_lock);
return r; return r;
} }
...@@ -801,7 +801,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor) ...@@ -801,7 +801,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor)
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
mutex_lock(&_minor_lock); spin_lock(&_minor_lock);
r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m); r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
if (r) { if (r) {
...@@ -817,7 +817,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor) ...@@ -817,7 +817,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor)
*minor = m; *minor = m;
out: out:
mutex_unlock(&_minor_lock); spin_unlock(&_minor_lock);
return r; return r;
} }
...@@ -887,9 +887,9 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent) ...@@ -887,9 +887,9 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
init_waitqueue_head(&md->eventq); init_waitqueue_head(&md->eventq);
/* Populate the mapping, nobody knows we exist yet */ /* Populate the mapping, nobody knows we exist yet */
mutex_lock(&_minor_lock); spin_lock(&_minor_lock);
old_md = idr_replace(&_minor_idr, md, minor); old_md = idr_replace(&_minor_idr, md, minor);
mutex_unlock(&_minor_lock); spin_unlock(&_minor_lock);
BUG_ON(old_md != MINOR_ALLOCED); BUG_ON(old_md != MINOR_ALLOCED);
...@@ -1020,13 +1020,13 @@ static struct mapped_device *dm_find_md(dev_t dev) ...@@ -1020,13 +1020,13 @@ static struct mapped_device *dm_find_md(dev_t dev)
if (MAJOR(dev) != _major || minor >= (1 << MINORBITS)) if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
return NULL; return NULL;
mutex_lock(&_minor_lock); spin_lock(&_minor_lock);
md = idr_find(&_minor_idr, minor); md = idr_find(&_minor_idr, minor);
if (md && (md == MINOR_ALLOCED || (dm_disk(md)->first_minor != minor))) if (md && (md == MINOR_ALLOCED || (dm_disk(md)->first_minor != minor)))
md = NULL; md = NULL;
mutex_unlock(&_minor_lock); spin_unlock(&_minor_lock);
return md; return md;
} }
...@@ -1060,11 +1060,10 @@ void dm_put(struct mapped_device *md) ...@@ -1060,11 +1060,10 @@ void dm_put(struct mapped_device *md)
{ {
struct dm_table *map; struct dm_table *map;
if (atomic_dec_and_test(&md->holders)) { if (atomic_dec_and_lock(&md->holders, &_minor_lock)) {
map = dm_get_table(md); map = dm_get_table(md);
mutex_lock(&_minor_lock);
idr_replace(&_minor_idr, MINOR_ALLOCED, dm_disk(md)->first_minor); idr_replace(&_minor_idr, MINOR_ALLOCED, dm_disk(md)->first_minor);
mutex_unlock(&_minor_lock); spin_unlock(&_minor_lock);
if (!dm_suspended(md)) { if (!dm_suspended(md)) {
dm_table_presuspend_targets(map); dm_table_presuspend_targets(map);
dm_table_postsuspend_targets(map); dm_table_postsuspend_targets(map);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment