diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-07-31 04:12:02 -0400 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 00:56:42 -0500 |
commit | 28935ab5163c49ca5c199d67335e5e3c72c50853 (patch) | |
tree | 736937f8745865b06a21822f9b619d3dd4baf950 /drivers/md | |
parent | c4d951ddb66fe1d087447b0ba65c4fa4446f1083 (diff) |
bcache: Use ida for bcache block dev minor
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bcache/super.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index fa1d53087f88..70708ab0b8f9 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/buffer_head.h> | 16 | #include <linux/buffer_head.h> |
17 | #include <linux/debugfs.h> | 17 | #include <linux/debugfs.h> |
18 | #include <linux/genhd.h> | 18 | #include <linux/genhd.h> |
19 | #include <linux/idr.h> | ||
19 | #include <linux/kthread.h> | 20 | #include <linux/kthread.h> |
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
21 | #include <linux/random.h> | 22 | #include <linux/random.h> |
@@ -50,7 +51,8 @@ struct mutex bch_register_lock; | |||
50 | LIST_HEAD(bch_cache_sets); | 51 | LIST_HEAD(bch_cache_sets); |
51 | static LIST_HEAD(uncached_devices); | 52 | static LIST_HEAD(uncached_devices); |
52 | 53 | ||
53 | static int bcache_major, bcache_minor; | 54 | static int bcache_major; |
55 | static DEFINE_IDA(bcache_minor); | ||
54 | static wait_queue_head_t unregister_wait; | 56 | static wait_queue_head_t unregister_wait; |
55 | struct workqueue_struct *bcache_wq; | 57 | struct workqueue_struct *bcache_wq; |
56 | 58 | ||
@@ -731,8 +733,10 @@ static void bcache_device_free(struct bcache_device *d) | |||
731 | del_gendisk(d->disk); | 733 | del_gendisk(d->disk); |
732 | if (d->disk && d->disk->queue) | 734 | if (d->disk && d->disk->queue) |
733 | blk_cleanup_queue(d->disk->queue); | 735 | blk_cleanup_queue(d->disk->queue); |
734 | if (d->disk) | 736 | if (d->disk) { |
737 | ida_simple_remove(&bcache_minor, d->disk->first_minor); | ||
735 | put_disk(d->disk); | 738 | put_disk(d->disk); |
739 | } | ||
736 | 740 | ||
737 | bio_split_pool_free(&d->bio_split_hook); | 741 | bio_split_pool_free(&d->bio_split_hook); |
738 | if (d->unaligned_bvec) | 742 | if (d->unaligned_bvec) |
@@ -756,6 +760,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, | |||
756 | { | 760 | { |
757 | struct request_queue *q; | 761 | struct request_queue *q; |
758 | size_t n; | 762 | size_t n; |
763 | int minor; | ||
759 | 764 | ||
760 | if (!d->stripe_size) | 765 | if (!d->stripe_size) |
761 | d->stripe_size = 1 << 31; | 766 | d->stripe_size = 1 << 31; |
@@ -783,22 +788,31 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, | |||
783 | if (!d->full_dirty_stripes) | 788 | if (!d->full_dirty_stripes) |
784 | return -ENOMEM; | 789 | return -ENOMEM; |
785 | 790 | ||
791 | minor = ida_simple_get(&bcache_minor, 0, MINORMASK + 1, GFP_KERNEL); | ||
792 | if (minor < 0) | ||
793 | return minor; | ||
794 | |||
786 | if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || | 795 | if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || |
787 | !(d->unaligned_bvec = mempool_create_kmalloc_pool(1, | 796 | !(d->unaligned_bvec = mempool_create_kmalloc_pool(1, |
788 | sizeof(struct bio_vec) * BIO_MAX_PAGES)) || | 797 | sizeof(struct bio_vec) * BIO_MAX_PAGES)) || |
789 | bio_split_pool_init(&d->bio_split_hook) || | 798 | bio_split_pool_init(&d->bio_split_hook) || |
790 | !(d->disk = alloc_disk(1)) || | 799 | !(d->disk = alloc_disk(1))) { |
791 | !(q = blk_alloc_queue(GFP_KERNEL))) | 800 | ida_simple_remove(&bcache_minor, minor); |
792 | return -ENOMEM; | 801 | return -ENOMEM; |
802 | } | ||
793 | 803 | ||
794 | set_capacity(d->disk, sectors); | 804 | set_capacity(d->disk, sectors); |
795 | snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", bcache_minor); | 805 | snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", minor); |
796 | 806 | ||
797 | d->disk->major = bcache_major; | 807 | d->disk->major = bcache_major; |
798 | d->disk->first_minor = bcache_minor++; | 808 | d->disk->first_minor = minor; |
799 | d->disk->fops = &bcache_ops; | 809 | d->disk->fops = &bcache_ops; |
800 | d->disk->private_data = d; | 810 | d->disk->private_data = d; |
801 | 811 | ||
812 | q = blk_alloc_queue(GFP_KERNEL); | ||
813 | if (!q) | ||
814 | return -ENOMEM; | ||
815 | |||
802 | blk_queue_make_request(q, NULL); | 816 | blk_queue_make_request(q, NULL); |
803 | d->disk->queue = q; | 817 | d->disk->queue = q; |
804 | q->queuedata = d; | 818 | q->queuedata = d; |