Commit 07affbb1 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] bdget_disk()

	New helper - bdget_disk(gendisk, partition)
	invalidate_device() replaced with invalidate_partition(disk, part)
parent 5e3ecdac
...@@ -3885,7 +3885,7 @@ static int floppy_read_block_0(struct gendisk *disk) ...@@ -3885,7 +3885,7 @@ static int floppy_read_block_0(struct gendisk *disk)
struct block_device *bdev; struct block_device *bdev;
int ret; int ret;
bdev = bdget(MKDEV(disk->major, disk->first_minor)); bdev = bdget_disk(disk, 0);
if (!bdev) { if (!bdev) {
printk("No block device for %s\n", disk->disk_name); printk("No block device for %s\n", disk->disk_name);
BUG(); BUG();
......
...@@ -3995,7 +3995,7 @@ static int floppy_read_block_0(struct gendisk *disk) ...@@ -3995,7 +3995,7 @@ static int floppy_read_block_0(struct gendisk *disk)
struct block_device *bdev; struct block_device *bdev;
int ret; int ret;
bdev = bdget(MKDEV(disk->major, disk->first_minor)); bdev = bdget_disk(disk, 0);
if (!bdev) { if (!bdev) {
printk("No block device for %s\n", disk->disk_name); printk("No block device for %s\n", disk->disk_name);
BUG(); BUG();
......
...@@ -721,6 +721,17 @@ int bdev_read_only(struct block_device *bdev) ...@@ -721,6 +721,17 @@ int bdev_read_only(struct block_device *bdev)
return disk->policy; return disk->policy;
} }
int invalidate_partition(struct gendisk *disk, int index)
{
int res = 0;
struct block_device *bdev = bdget_disk(disk, index);
if (bdev)
res = __invalidate_device(bdev, 1);
bdput(bdev);
return res;
}
EXPORT_SYMBOL(bdev_read_only); EXPORT_SYMBOL(bdev_read_only);
EXPORT_SYMBOL(set_device_ro); EXPORT_SYMBOL(set_device_ro);
EXPORT_SYMBOL(set_disk_ro); EXPORT_SYMBOL(set_disk_ro);
EXPORT_SYMBOL(invalidate_partition);
...@@ -62,7 +62,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg *arg) ...@@ -62,7 +62,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg *arg)
if (disk->part[part - 1]->nr_sects == 0) if (disk->part[part - 1]->nr_sects == 0)
return -ENXIO; return -ENXIO;
/* partition in use? Incomplete check for now. */ /* partition in use? Incomplete check for now. */
bdevp = bdget(MKDEV(disk->major, disk->first_minor) + part); bdevp = bdget_disk(disk, part);
if (!bdevp) if (!bdevp)
return -ENOMEM; return -ENOMEM;
if (bd_claim(bdevp, &holder) < 0) { if (bd_claim(bdevp, &holder) < 0) {
......
...@@ -450,11 +450,11 @@ static int __info(struct mapped_device *md, struct dm_ioctl *param) ...@@ -450,11 +450,11 @@ static int __info(struct mapped_device *md, struct dm_ioctl *param)
if (dm_suspended(md)) if (dm_suspended(md))
param->flags |= DM_SUSPEND_FLAG; param->flags |= DM_SUSPEND_FLAG;
param->dev = MKDEV(disk->major, disk->first_minor); bdev = bdget_disk(disk, 0);
bdev = bdget(param->dev);
if (!bdev) if (!bdev)
return -ENXIO; return -ENXIO;
param->dev = bdev->bd_dev;
param->open_count = bdev->bd_openers; param->open_count = bdev->bd_openers;
bdput(bdev); bdput(bdev);
......
...@@ -1684,7 +1684,7 @@ static int do_md_stop(mddev_t * mddev, int ro) ...@@ -1684,7 +1684,7 @@ static int do_md_stop(mddev_t * mddev, int ro)
del_timer_sync(&mddev->safemode_timer); del_timer_sync(&mddev->safemode_timer);
invalidate_device(mk_kdev(disk->major, disk->first_minor), 1); invalidate_partition(disk, 0);
if (ro) { if (ro) {
err = -ENXIO; err = -ENXIO;
......
...@@ -535,7 +535,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * ...@@ -535,7 +535,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
} else { } else {
struct hd_struct *p; struct hd_struct *p;
struct block_device *whole; struct block_device *whole;
whole = bdget(MKDEV(disk->major, disk->first_minor)); whole = bdget_disk(disk, 0);
ret = -ENOMEM; ret = -ENOMEM;
if (!whole) if (!whole)
goto out_first; goto out_first;
......
...@@ -365,16 +365,6 @@ int __invalidate_device(struct block_device *bdev, int do_sync) ...@@ -365,16 +365,6 @@ int __invalidate_device(struct block_device *bdev, int do_sync)
return res; return res;
} }
int invalidate_device(kdev_t dev, int do_sync)
{
int res = 0;
struct block_device *bdev = bdget(kdev_t_to_nr(dev));
if (bdev)
res = __invalidate_device(bdev, do_sync);
bdput(bdev);
return res;
}
static int can_unuse(struct inode *inode) static int can_unuse(struct inode *inode)
{ {
if (inode->i_state) if (inode->i_state)
......
...@@ -311,7 +311,7 @@ void register_disk(struct gendisk *disk) ...@@ -311,7 +311,7 @@ void register_disk(struct gendisk *disk)
if (!get_capacity(disk)) if (!get_capacity(disk))
return; return;
bdev = bdget(MKDEV(disk->major, disk->first_minor)); bdev = bdget_disk(disk, 0);
if (blkdev_get(bdev, FMODE_READ, 0, BDEV_RAW) < 0) if (blkdev_get(bdev, FMODE_READ, 0, BDEV_RAW) < 0)
return; return;
state = check_partition(disk, bdev); state = check_partition(disk, bdev);
...@@ -336,13 +336,12 @@ void register_disk(struct gendisk *disk) ...@@ -336,13 +336,12 @@ void register_disk(struct gendisk *disk)
int rescan_partitions(struct gendisk *disk, struct block_device *bdev) int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
{ {
kdev_t dev = to_kdev_t(bdev->bd_dev);
struct parsed_partitions *state; struct parsed_partitions *state;
int p, res; int p, res;
if (bdev->bd_part_count) if (bdev->bd_part_count)
return -EBUSY; return -EBUSY;
res = invalidate_device(dev, 1); res = invalidate_partition(disk, 0);
if (res) if (res)
return res; return res;
bdev->bd_invalidated = 0; bdev->bd_invalidated = 0;
...@@ -391,18 +390,14 @@ unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p) ...@@ -391,18 +390,14 @@ unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
void del_gendisk(struct gendisk *disk) void del_gendisk(struct gendisk *disk)
{ {
int max_p = disk->minors;
kdev_t devp;
int p; int p;
/* invalidate stuff */ /* invalidate stuff */
for (p = max_p - 1; p > 0; p--) { for (p = disk->minors - 1; p > 0; p--) {
devp = mk_kdev(disk->major,disk->first_minor + p); invalidate_partition(disk, p);
invalidate_device(devp, 1);
delete_partition(disk, p); delete_partition(disk, p);
} }
devp = mk_kdev(disk->major,disk->first_minor); invalidate_partition(disk, 0);
invalidate_device(devp, 1);
disk->capacity = 0; disk->capacity = 0;
disk->flags &= ~GENHD_FL_UP; disk->flags &= ~GENHD_FL_UP;
unlink_gendisk(disk); unlink_gendisk(disk);
......
...@@ -1105,7 +1105,7 @@ extern int fs_may_remount_ro(struct super_block *); ...@@ -1105,7 +1105,7 @@ extern int fs_may_remount_ro(struct super_block *);
extern int check_disk_change(struct block_device *); extern int check_disk_change(struct block_device *);
extern int invalidate_inodes(struct super_block *); extern int invalidate_inodes(struct super_block *);
extern int __invalidate_device(struct block_device *, int); extern int __invalidate_device(struct block_device *, int);
extern int invalidate_device(kdev_t, int); extern int invalidate_partition(struct gendisk *, int);
unsigned long invalidate_mapping_pages(struct address_space *mapping, unsigned long invalidate_mapping_pages(struct address_space *mapping,
pgoff_t start, pgoff_t end); pgoff_t start, pgoff_t end);
unsigned long invalidate_inode_pages(struct address_space *mapping); unsigned long invalidate_inode_pages(struct address_space *mapping);
......
...@@ -367,6 +367,11 @@ extern void blk_register_region(dev_t dev, unsigned long range, ...@@ -367,6 +367,11 @@ extern void blk_register_region(dev_t dev, unsigned long range,
void *data); void *data);
extern void blk_unregister_region(dev_t dev, unsigned long range); extern void blk_unregister_region(dev_t dev, unsigned long range);
static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
{
return bdget(MKDEV(disk->major, disk->first_minor) + index);
}
#endif #endif
#endif #endif
...@@ -188,7 +188,6 @@ EXPORT_SYMBOL(files_lock); ...@@ -188,7 +188,6 @@ EXPORT_SYMBOL(files_lock);
EXPORT_SYMBOL(check_disk_change); EXPORT_SYMBOL(check_disk_change);
EXPORT_SYMBOL(invalidate_bdev); EXPORT_SYMBOL(invalidate_bdev);
EXPORT_SYMBOL(invalidate_inodes); EXPORT_SYMBOL(invalidate_inodes);
EXPORT_SYMBOL(invalidate_device);
EXPORT_SYMBOL(__invalidate_device); EXPORT_SYMBOL(__invalidate_device);
EXPORT_SYMBOL(invalidate_inode_pages); EXPORT_SYMBOL(invalidate_inode_pages);
EXPORT_SYMBOL_GPL(invalidate_inode_pages2); EXPORT_SYMBOL_GPL(invalidate_inode_pages2);
......
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