From cf471bb67012a65d76e84dd12c64a1450eb2ffe4 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Mon, 26 Jun 2006 00:27:21 -0700 Subject: [PATCH] --- yaml --- r: 30335 b: refs/heads/master c: ba61fdd17d73ddb5c892a9f12383c6c560a20d56 h: refs/heads/master i: 30333: a6be5cc3a5e7bb75895b5174467c6366b93696c0 30331: f1520bc1bbb5e2020c8fdb1f0db2f6b17f6806b9 30327: 354289f807bf08175ebce50cf90f490c92933191 30319: a60a77b50394d2c76175b39c744c42eb3f09f6a6 30303: 63605b50b5a0977966c0938208e9d049fec0b05d 30271: 9144775590c99a54ee9fdda2e4ac2c835a52d5c6 30207: 589ad079c10345de9d684b9e90fc5c2d801c6fff v: v3 --- [refs] | 2 +- trunk/drivers/md/dm.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index 97259dce9351..0fa04d8df010 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 5806f07cd2c32920d5105e0f9ff3117338f34eec +refs/heads/master: ba61fdd17d73ddb5c892a9f12383c6c560a20d56 diff --git a/trunk/drivers/md/dm.c b/trunk/drivers/md/dm.c index 4d710b7a133b..87d8ca1121e2 100644 --- a/trunk/drivers/md/dm.c +++ b/trunk/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);