Commit 426f67eb authored by Patrick Mochel's avatar Patrick Mochel

block devices: use list and lock in block_subsys, instead of those defined in genhd.c.

Since block_subsys already contains a list and a lock, use those, instead
of defining our own static ones.

This allows struct gendisk::full_list to be removed. 

struct gendisk::list is also apparently unused, so it is removed also.
parent 93e8f330
...@@ -27,12 +27,8 @@ ...@@ -27,12 +27,8 @@
#include <linux/kmod.h> #include <linux/kmod.h>
static rwlock_t gendisk_lock; static struct subsystem block_subsys;
/*
* Global kernel list of partitioning information.
*/
static LIST_HEAD(gendisk_list);
struct blk_probe { struct blk_probe {
struct blk_probe *next; struct blk_probe *next;
...@@ -63,19 +59,19 @@ void blk_register_region(dev_t dev, unsigned long range, struct module *module, ...@@ -63,19 +59,19 @@ void blk_register_region(dev_t dev, unsigned long range, struct module *module,
p->dev = dev; p->dev = dev;
p->range = range; p->range = range;
p->data = data; p->data = data;
write_lock(&gendisk_lock); down_write(&block_subsys.rwsem);
for (s = &probes[index]; *s && (*s)->range < range; s = &(*s)->next) for (s = &probes[index]; *s && (*s)->range < range; s = &(*s)->next)
; ;
p->next = *s; p->next = *s;
*s = p; *s = p;
write_unlock(&gendisk_lock); up_write(&block_subsys.rwsem);
} }
void blk_unregister_region(dev_t dev, unsigned long range) void blk_unregister_region(dev_t dev, unsigned long range)
{ {
int index = dev_to_index(dev); int index = dev_to_index(dev);
struct blk_probe **s; struct blk_probe **s;
write_lock(&gendisk_lock); down_write(&block_subsys.rwsem);
for (s = &probes[index]; *s; s = &(*s)->next) { for (s = &probes[index]; *s; s = &(*s)->next) {
struct blk_probe *p = *s; struct blk_probe *p = *s;
if (p->dev == dev || p->range == range) { if (p->dev == dev || p->range == range) {
...@@ -84,7 +80,7 @@ void blk_unregister_region(dev_t dev, unsigned long range) ...@@ -84,7 +80,7 @@ void blk_unregister_region(dev_t dev, unsigned long range)
break; break;
} }
} }
write_unlock(&gendisk_lock); up_write(&block_subsys.rwsem);
} }
EXPORT_SYMBOL(blk_register_region); EXPORT_SYMBOL(blk_register_region);
...@@ -112,9 +108,6 @@ static int exact_lock(dev_t dev, void *data) ...@@ -112,9 +108,6 @@ static int exact_lock(dev_t dev, void *data)
*/ */
void add_disk(struct gendisk *disk) void add_disk(struct gendisk *disk)
{ {
write_lock(&gendisk_lock);
list_add_tail(&disk->full_list, &gendisk_list);
write_unlock(&gendisk_lock);
disk->flags |= GENHD_FL_UP; disk->flags |= GENHD_FL_UP;
blk_register_region(MKDEV(disk->major, disk->first_minor), disk->minors, blk_register_region(MKDEV(disk->major, disk->first_minor), disk->minors,
NULL, exact_match, exact_lock, disk); NULL, exact_match, exact_lock, disk);
...@@ -126,9 +119,6 @@ EXPORT_SYMBOL(del_gendisk); ...@@ -126,9 +119,6 @@ EXPORT_SYMBOL(del_gendisk);
void unlink_gendisk(struct gendisk *disk) void unlink_gendisk(struct gendisk *disk)
{ {
write_lock(&gendisk_lock);
list_del_init(&disk->full_list);
write_unlock(&gendisk_lock);
blk_unregister_region(MKDEV(disk->major, disk->first_minor), blk_unregister_region(MKDEV(disk->major, disk->first_minor),
disk->minors); disk->minors);
} }
...@@ -149,7 +139,7 @@ get_gendisk(dev_t dev, int *part) ...@@ -149,7 +139,7 @@ get_gendisk(dev_t dev, int *part)
unsigned best = ~0U; unsigned best = ~0U;
retry: retry:
read_lock(&gendisk_lock); down_read(&block_subsys.rwsem);
for (p = probes[index]; p; p = p->next) { for (p = probes[index]; p; p = p->next) {
struct gendisk *(*probe)(dev_t, int *, void *); struct gendisk *(*probe)(dev_t, int *, void *);
struct module *owner; struct module *owner;
...@@ -157,7 +147,7 @@ get_gendisk(dev_t dev, int *part) ...@@ -157,7 +147,7 @@ get_gendisk(dev_t dev, int *part)
if (p->dev > dev || p->dev + p->range <= dev) if (p->dev > dev || p->dev + p->range <= dev)
continue; continue;
if (p->range >= best) { if (p->range >= best) {
read_unlock(&gendisk_lock); up_read(&block_subsys.rwsem);
return NULL; return NULL;
} }
if (!try_module_get(p->owner)) if (!try_module_get(p->owner))
...@@ -171,7 +161,7 @@ get_gendisk(dev_t dev, int *part) ...@@ -171,7 +161,7 @@ get_gendisk(dev_t dev, int *part)
module_put(owner); module_put(owner);
continue; continue;
} }
read_unlock(&gendisk_lock); up_read(&block_subsys.rwsem);
disk = probe(dev, part, data); disk = probe(dev, part, data);
/* Currently ->owner protects _only_ ->probe() itself. */ /* Currently ->owner protects _only_ ->probe() itself. */
module_put(owner); module_put(owner);
...@@ -179,7 +169,7 @@ get_gendisk(dev_t dev, int *part) ...@@ -179,7 +169,7 @@ get_gendisk(dev_t dev, int *part)
return disk; return disk;
goto retry; goto retry;
} }
read_unlock(&gendisk_lock); up_read(&block_subsys.rwsem);
return NULL; return NULL;
} }
...@@ -190,23 +180,24 @@ static void *part_start(struct seq_file *part, loff_t *pos) ...@@ -190,23 +180,24 @@ static void *part_start(struct seq_file *part, loff_t *pos)
struct list_head *p; struct list_head *p;
loff_t l = *pos; loff_t l = *pos;
read_lock(&gendisk_lock); down_read(&block_subsys.rwsem);
list_for_each(p, &gendisk_list) list_for_each(p, &block_subsys.kset.list)
if (!l--) if (!l--)
return list_entry(p, struct gendisk, full_list); return list_entry(p, struct gendisk, kobj.entry);
return NULL; return NULL;
} }
static void *part_next(struct seq_file *part, void *v, loff_t *pos) static void *part_next(struct seq_file *part, void *v, loff_t *pos)
{ {
struct list_head *p = ((struct gendisk *)v)->full_list.next; struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
++*pos; ++*pos;
return p==&gendisk_list ? NULL : list_entry(p, struct gendisk, full_list); return p==&block_subsys.kset.list ? NULL :
list_entry(p, struct gendisk, kobj.entry);
} }
static void part_stop(struct seq_file *part, void *v) static void part_stop(struct seq_file *part, void *v)
{ {
read_unlock(&gendisk_lock); up_read(&block_subsys.rwsem);
} }
static int show_partition(struct seq_file *part, void *v) static int show_partition(struct seq_file *part, void *v)
...@@ -215,7 +206,7 @@ static int show_partition(struct seq_file *part, void *v) ...@@ -215,7 +206,7 @@ static int show_partition(struct seq_file *part, void *v)
int n; int n;
char buf[64]; char buf[64];
if (&sgp->full_list == gendisk_list.next) if (&sgp->kobj.entry == block_subsys.kset.list.next)
seq_puts(part, "major minor #blocks name\n\n"); seq_puts(part, "major minor #blocks name\n\n");
/* Don't show non-partitionable devices or empty devices */ /* Don't show non-partitionable devices or empty devices */
...@@ -258,13 +249,10 @@ static struct gendisk *base_probe(dev_t dev, int *part, void *data) ...@@ -258,13 +249,10 @@ static struct gendisk *base_probe(dev_t dev, int *part, void *data)
return NULL; return NULL;
} }
struct subsystem block_subsys;
int __init device_init(void) int __init device_init(void)
{ {
struct blk_probe *base = kmalloc(sizeof(struct blk_probe), GFP_KERNEL); struct blk_probe *base = kmalloc(sizeof(struct blk_probe), GFP_KERNEL);
int i; int i;
rwlock_init(&gendisk_lock);
memset(base, 0, sizeof(struct blk_probe)); memset(base, 0, sizeof(struct blk_probe));
base->dev = MKDEV(1,0); base->dev = MKDEV(1,0);
base->range = MKDEV(MAX_BLKDEV-1, 255) - base->dev + 1; base->range = MKDEV(MAX_BLKDEV-1, 255) - base->dev + 1;
...@@ -390,7 +378,10 @@ static struct kobj_type ktype_block = { ...@@ -390,7 +378,10 @@ static struct kobj_type ktype_block = {
.default_attrs = default_attrs, .default_attrs = default_attrs,
}; };
decl_subsys(block,&ktype_block);
/* declare block_subsys. */
static decl_subsys(block,&ktype_block);
struct gendisk *alloc_disk(int minors) struct gendisk *alloc_disk(int minors)
{ {
...@@ -411,7 +402,6 @@ struct gendisk *alloc_disk(int minors) ...@@ -411,7 +402,6 @@ struct gendisk *alloc_disk(int minors)
disk->minor_shift++; disk->minor_shift++;
kobj_set_kset_s(disk,block_subsys); kobj_set_kset_s(disk,block_subsys);
kobject_init(&disk->kobj); kobject_init(&disk->kobj);
INIT_LIST_HEAD(&disk->full_list);
rand_initialize_disk(disk); rand_initialize_disk(disk);
} }
return disk; return disk;
......
...@@ -85,8 +85,6 @@ struct gendisk { ...@@ -85,8 +85,6 @@ struct gendisk {
struct request_queue *queue; struct request_queue *queue;
void *private_data; void *private_data;
sector_t capacity; sector_t capacity;
struct list_head list;
struct list_head full_list;
int flags; int flags;
int number; /* devfs crap */ int number; /* devfs crap */
......
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