aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2006-06-26 00:27:21 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 09:58:34 -0700
commitba61fdd17d73ddb5c892a9f12383c6c560a20d56 (patch)
tree7623bd742e2c142a8c5a1d8e5b940095b8673f3f /drivers
parent[PATCH] lib: add idr_replace (diff)
downloadlinux-dev-ba61fdd17d73ddb5c892a9f12383c6c560a20d56.tar.xz
linux-dev-ba61fdd17d73ddb5c892a9f12383c6c560a20d56.zip
[PATCH] dm: fix idr minor allocation
One part of the system can attempt to use a mapped device before another has finished initialising it or while it is being freed. This patch introduces a place holder value, MINOR_ALLOCED, to mark the minor as allocated but in a state where it can't be used, such as mid-allocation or mid-free. At the end of the initialization, it replaces the place holder with the pointer to the mapped_device, making it available to the rest of the dm subsystem. [akpm: too late for 2.6.17 - suitable for 2.6.17.x after it has settled] Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/dm.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 4d710b7a133b..87d8ca1121e2 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -54,6 +54,8 @@ union map_info *dm_get_mapinfo(struct bio *bio)
return NULL;
}
+#define MINOR_ALLOCED ((void *)-1)
+
/*
* Bits for the md->flags field.
*/
@@ -777,7 +779,7 @@ static int specific_minor(struct mapped_device *md, unsigned int minor)
goto out;
}
- r = idr_get_new_above(&_minor_idr, md, minor, &m);
+ r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m);
if (r) {
goto out;
}
@@ -806,7 +808,7 @@ static int next_free_minor(struct mapped_device *md, unsigned int *minor)
goto out;
}
- r = idr_get_new(&_minor_idr, md, &m);
+ r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
if (r) {
goto out;
}
@@ -833,6 +835,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
{
int r;
struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
+ void *old_md;
if (!md) {
DMWARN("unable to allocate device, out of memory.");
@@ -888,6 +891,13 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
init_waitqueue_head(&md->wait);
init_waitqueue_head(&md->eventq);
+ /* Populate the mapping, nobody knows we exist yet */
+ mutex_lock(&_minor_lock);
+ old_md = idr_replace(&_minor_idr, md, minor);
+ mutex_unlock(&_minor_lock);
+
+ BUG_ON(old_md != MINOR_ALLOCED);
+
return md;
bad4:
@@ -1018,7 +1028,7 @@ static struct mapped_device *dm_find_md(dev_t dev)
mutex_lock(&_minor_lock);
md = idr_find(&_minor_idr, minor);
- if (!md || (dm_disk(md)->first_minor != minor))
+ if (md && (md == MINOR_ALLOCED || (dm_disk(md)->first_minor != minor)))
md = NULL;
mutex_unlock(&_minor_lock);
@@ -1057,6 +1067,9 @@ void dm_put(struct mapped_device *md)
if (atomic_dec_and_test(&md->holders)) {
map = dm_get_table(md);
+ mutex_lock(&_minor_lock);
+ idr_replace(&_minor_idr, MINOR_ALLOCED, dm_disk(md)->first_minor);
+ mutex_unlock(&_minor_lock);
if (!dm_suspended(md)) {
dm_table_presuspend_targets(map);
dm_table_postsuspend_targets(map);