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