aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@gmail.com>2011-05-26 15:06:50 -0400
committerJens Axboe <jaxboe@fusionio.com>2011-05-26 15:06:50 -0400
commitaf46566885a373b0a526932484cd8fef8de7b598 (patch)
treee95098d113f040f9eb497965b8285d10a6b59ab9 /drivers/block
parent315980c8688c4b06713c1a5fe9d64cdf8ab57a72 (diff)
brd: handle on-demand devices correctly
When finding or allocating a ram disk device, brd_probe() did not take partition numbers into account so that it can result to a different device. Consider following example (I set CONFIG_BLK_DEV_RAM_COUNT=4 for simplicity) : $ sudo modprobe brd max_part=15 $ ls -l /dev/ram* brw-rw---- 1 root disk 1, 0 2011-05-25 15:41 /dev/ram0 brw-rw---- 1 root disk 1, 16 2011-05-25 15:41 /dev/ram1 brw-rw---- 1 root disk 1, 32 2011-05-25 15:41 /dev/ram2 brw-rw---- 1 root disk 1, 48 2011-05-25 15:41 /dev/ram3 $ sudo mknod /dev/ram4 b 1 64 $ sudo dd if=/dev/zero of=/dev/ram4 bs=4k count=256 256+0 records in 256+0 records out 1048576 bytes (1.0 MB) copied, 0.00215578 s, 486 MB/s namhyung@leonhard:linux$ ls -l /dev/ram* brw-rw---- 1 root disk 1, 0 2011-05-25 15:41 /dev/ram0 brw-rw---- 1 root disk 1, 16 2011-05-25 15:41 /dev/ram1 brw-rw---- 1 root disk 1, 32 2011-05-25 15:41 /dev/ram2 brw-rw---- 1 root disk 1, 48 2011-05-25 15:41 /dev/ram3 brw-r--r-- 1 root root 1, 64 2011-05-25 15:45 /dev/ram4 brw-rw---- 1 root disk 1, 1024 2011-05-25 15:44 /dev/ram64 After this patch, /dev/ram4 - instead of /dev/ram64 - was accessed correctly. In addition, 'range' passed to blk_register_region() should include all range of dev_t that RAMDISK_MAJOR can address. It does not need to be limited by partition numbers unless 'rd_nr' param was specified. Signed-off-by: Namhyung Kim <namhyung@gmail.com> Cc: Laurent Vivier <Laurent.Vivier@bull.net> Cc: stable@kernel.org Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/brd.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index e9a19d99f928..b1efa8f9ff42 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -548,7 +548,7 @@ static struct kobject *brd_probe(dev_t dev, int *part, void *data)
548 struct kobject *kobj; 548 struct kobject *kobj;
549 549
550 mutex_lock(&brd_devices_mutex); 550 mutex_lock(&brd_devices_mutex);
551 brd = brd_init_one(dev & MINORMASK); 551 brd = brd_init_one(MINOR(dev) >> part_shift);
552 kobj = brd ? get_disk(brd->brd_disk) : ERR_PTR(-ENOMEM); 552 kobj = brd ? get_disk(brd->brd_disk) : ERR_PTR(-ENOMEM);
553 mutex_unlock(&brd_devices_mutex); 553 mutex_unlock(&brd_devices_mutex);
554 554
@@ -589,10 +589,10 @@ static int __init brd_init(void)
589 589
590 if (rd_nr) { 590 if (rd_nr) {
591 nr = rd_nr; 591 nr = rd_nr;
592 range = rd_nr; 592 range = rd_nr << part_shift;
593 } else { 593 } else {
594 nr = CONFIG_BLK_DEV_RAM_COUNT; 594 nr = CONFIG_BLK_DEV_RAM_COUNT;
595 range = 1UL << (MINORBITS - part_shift); 595 range = 1UL << MINORBITS;
596 } 596 }
597 597
598 if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) 598 if (register_blkdev(RAMDISK_MAJOR, "ramdisk"))
@@ -631,7 +631,7 @@ static void __exit brd_exit(void)
631 unsigned long range; 631 unsigned long range;
632 struct brd_device *brd, *next; 632 struct brd_device *brd, *next;
633 633
634 range = rd_nr ? rd_nr : 1UL << (MINORBITS - part_shift); 634 range = rd_nr ? rd_nr << part_shift : 1UL << MINORBITS;
635 635
636 list_for_each_entry_safe(brd, next, &brd_devices, brd_list) 636 list_for_each_entry_safe(brd, next, &brd_devices, brd_list)
637 brd_del_one(brd); 637 brd_del_one(brd);