Commit e49fbbbf authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: split block_class_lock

Split the block_class_lock mutex into one each to protect bdev_map
and major_names.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 62b508f8
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "blk.h" #include "blk.h"
static DEFINE_MUTEX(block_class_lock);
static struct kobject *block_depr; static struct kobject *block_depr;
struct bdev_map { struct bdev_map {
...@@ -37,6 +36,7 @@ struct bdev_map { ...@@ -37,6 +36,7 @@ struct bdev_map {
int (*lock)(dev_t, void *); int (*lock)(dev_t, void *);
void *data; void *data;
} *bdev_map[255]; } *bdev_map[255];
static DEFINE_MUTEX(bdev_map_lock);
/* for extended dynamic devt allocation, currently only one major is used */ /* for extended dynamic devt allocation, currently only one major is used */
#define NR_EXT_DEVT (1 << MINORBITS) #define NR_EXT_DEVT (1 << MINORBITS)
...@@ -403,6 +403,7 @@ static struct blk_major_name { ...@@ -403,6 +403,7 @@ static struct blk_major_name {
int major; int major;
char name[16]; char name[16];
} *major_names[BLKDEV_MAJOR_HASH_SIZE]; } *major_names[BLKDEV_MAJOR_HASH_SIZE];
static DEFINE_MUTEX(major_names_lock);
/* index in the above - for now: assume no multimajor ranges */ /* index in the above - for now: assume no multimajor ranges */
static inline int major_to_index(unsigned major) static inline int major_to_index(unsigned major)
...@@ -415,11 +416,11 @@ void blkdev_show(struct seq_file *seqf, off_t offset) ...@@ -415,11 +416,11 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
{ {
struct blk_major_name *dp; struct blk_major_name *dp;
mutex_lock(&block_class_lock); mutex_lock(&major_names_lock);
for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next) for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next)
if (dp->major == offset) if (dp->major == offset)
seq_printf(seqf, "%3d %s\n", dp->major, dp->name); seq_printf(seqf, "%3d %s\n", dp->major, dp->name);
mutex_unlock(&block_class_lock); mutex_unlock(&major_names_lock);
} }
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
...@@ -448,7 +449,7 @@ int register_blkdev(unsigned int major, const char *name) ...@@ -448,7 +449,7 @@ int register_blkdev(unsigned int major, const char *name)
struct blk_major_name **n, *p; struct blk_major_name **n, *p;
int index, ret = 0; int index, ret = 0;
mutex_lock(&block_class_lock); mutex_lock(&major_names_lock);
/* temporary */ /* temporary */
if (major == 0) { if (major == 0) {
...@@ -501,7 +502,7 @@ int register_blkdev(unsigned int major, const char *name) ...@@ -501,7 +502,7 @@ int register_blkdev(unsigned int major, const char *name)
kfree(p); kfree(p);
} }
out: out:
mutex_unlock(&block_class_lock); mutex_unlock(&major_names_lock);
return ret; return ret;
} }
...@@ -513,7 +514,7 @@ void unregister_blkdev(unsigned int major, const char *name) ...@@ -513,7 +514,7 @@ void unregister_blkdev(unsigned int major, const char *name)
struct blk_major_name *p = NULL; struct blk_major_name *p = NULL;
int index = major_to_index(major); int index = major_to_index(major);
mutex_lock(&block_class_lock); mutex_lock(&major_names_lock);
for (n = &major_names[index]; *n; n = &(*n)->next) for (n = &major_names[index]; *n; n = &(*n)->next)
if ((*n)->major == major) if ((*n)->major == major)
break; break;
...@@ -523,7 +524,7 @@ void unregister_blkdev(unsigned int major, const char *name) ...@@ -523,7 +524,7 @@ void unregister_blkdev(unsigned int major, const char *name)
p = *n; p = *n;
*n = p->next; *n = p->next;
} }
mutex_unlock(&block_class_lock); mutex_unlock(&major_names_lock);
kfree(p); kfree(p);
} }
...@@ -674,7 +675,7 @@ void blk_register_region(dev_t devt, unsigned long range, struct module *module, ...@@ -674,7 +675,7 @@ void blk_register_region(dev_t devt, unsigned long range, struct module *module,
p->data = data; p->data = data;
} }
mutex_lock(&block_class_lock); mutex_lock(&bdev_map_lock);
for (i = 0, p -= n; i < n; i++, p++, index++) { for (i = 0, p -= n; i < n; i++, p++, index++) {
struct bdev_map **s = &bdev_map[index % 255]; struct bdev_map **s = &bdev_map[index % 255];
while (*s && (*s)->range < range) while (*s && (*s)->range < range)
...@@ -682,7 +683,7 @@ void blk_register_region(dev_t devt, unsigned long range, struct module *module, ...@@ -682,7 +683,7 @@ void blk_register_region(dev_t devt, unsigned long range, struct module *module,
p->next = *s; p->next = *s;
*s = p; *s = p;
} }
mutex_unlock(&block_class_lock); mutex_unlock(&bdev_map_lock);
} }
EXPORT_SYMBOL(blk_register_region); EXPORT_SYMBOL(blk_register_region);
...@@ -693,7 +694,7 @@ void blk_unregister_region(dev_t devt, unsigned long range) ...@@ -693,7 +694,7 @@ void blk_unregister_region(dev_t devt, unsigned long range)
unsigned i; unsigned i;
struct bdev_map *found = NULL; struct bdev_map *found = NULL;
mutex_lock(&block_class_lock); mutex_lock(&bdev_map_lock);
for (i = 0; i < min(n, 255u); i++, index++) { for (i = 0; i < min(n, 255u); i++, index++) {
struct bdev_map **s; struct bdev_map **s;
for (s = &bdev_map[index % 255]; *s; s = &(*s)->next) { for (s = &bdev_map[index % 255]; *s; s = &(*s)->next) {
...@@ -706,7 +707,7 @@ void blk_unregister_region(dev_t devt, unsigned long range) ...@@ -706,7 +707,7 @@ void blk_unregister_region(dev_t devt, unsigned long range)
} }
} }
} }
mutex_unlock(&block_class_lock); mutex_unlock(&bdev_map_lock);
kfree(found); kfree(found);
} }
EXPORT_SYMBOL(blk_unregister_region); EXPORT_SYMBOL(blk_unregister_region);
...@@ -1037,7 +1038,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno) ...@@ -1037,7 +1038,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno)
unsigned long best = ~0UL; unsigned long best = ~0UL;
retry: retry:
mutex_lock(&block_class_lock); mutex_lock(&bdev_map_lock);
for (p = bdev_map[MAJOR(dev) % 255]; p; p = p->next) { for (p = bdev_map[MAJOR(dev) % 255]; p; p = p->next) {
struct kobject *(*probe)(dev_t, int *, void *); struct kobject *(*probe)(dev_t, int *, void *);
struct module *owner; struct module *owner;
...@@ -1058,7 +1059,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno) ...@@ -1058,7 +1059,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno)
module_put(owner); module_put(owner);
continue; continue;
} }
mutex_unlock(&block_class_lock); mutex_unlock(&bdev_map_lock);
kobj = probe(dev, partno, data); kobj = probe(dev, partno, data);
/* Currently ->owner protects _only_ ->probe() itself. */ /* Currently ->owner protects _only_ ->probe() itself. */
module_put(owner); module_put(owner);
...@@ -1066,7 +1067,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno) ...@@ -1066,7 +1067,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno)
return dev_to_disk(kobj_to_dev(kobj)); return dev_to_disk(kobj_to_dev(kobj));
goto retry; goto retry;
} }
mutex_unlock(&block_class_lock); mutex_unlock(&bdev_map_lock);
return NULL; return NULL;
} }
......
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