Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 273809
b: refs/heads/master
c: f992ae8
h: refs/heads/master
i:
  273807: f78d240
v: v3
  • Loading branch information
Tejun Heo authored and Jens Axboe committed Oct 24, 2011
1 parent 37368ed commit a91eae9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e67b77c791ca2778198c9e7088f3266ed2da7a55
refs/heads/master: f992ae801a7dec34a4ed99a6598bbbbfb82af4fb
8 changes: 8 additions & 0 deletions trunk/block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ void add_disk(struct gendisk *disk)
register_disk(disk);
blk_register_queue(disk);

/*
* Take an extra ref on queue which will be put on disk_release()
* so that it sticks around as long as @disk is there.
*/
WARN_ON_ONCE(blk_get_queue(disk->queue));

retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
"bdi");
WARN_ON(retval);
Expand Down Expand Up @@ -1095,6 +1101,8 @@ static void disk_release(struct device *dev)
disk_replace_part_tbl(disk, NULL);
free_part_stats(&disk->part0);
free_part_info(&disk->part0);
if (disk->queue)
blk_put_queue(disk->queue);
kfree(disk);
}
struct class block_class = {
Expand Down
13 changes: 8 additions & 5 deletions trunk/fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
{
struct gendisk *disk;
struct module *owner;
int ret;
int partno;
int perm = 0;
Expand All @@ -1110,6 +1111,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk)
goto out;
owner = disk->fops->owner;

disk_block_events(disk);
mutex_lock_nested(&bdev->bd_mutex, for_part);
Expand Down Expand Up @@ -1137,8 +1139,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
bdev->bd_disk = NULL;
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
module_put(disk->fops->owner);
put_disk(disk);
module_put(owner);
goto restart;
}
}
Expand Down Expand Up @@ -1194,8 +1196,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
goto out_unlock_bdev;
}
/* only one opener holds refs to the module and disk */
module_put(disk->fops->owner);
put_disk(disk);
module_put(owner);
}
bdev->bd_openers++;
if (for_part)
Expand All @@ -1215,8 +1217,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
out_unlock_bdev:
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
module_put(disk->fops->owner);
put_disk(disk);
module_put(owner);
out:
bdput(bdev);

Expand Down Expand Up @@ -1442,14 +1444,15 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner;

put_disk(disk);
module_put(owner);
disk_put_part(bdev->bd_part);
bdev->bd_part = NULL;
bdev->bd_disk = NULL;
if (bdev != bdev->bd_contains)
victim = bdev->bd_contains;
bdev->bd_contains = NULL;

put_disk(disk);
module_put(owner);
}
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
Expand Down

0 comments on commit a91eae9

Please sign in to comment.