Commit 9df6c299 authored by Jan Kara's avatar Jan Kara Committed by Jens Axboe

genhd: Add helper put_disk_and_module()

Add a proper counterpart to get_disk_and_module() -
put_disk_and_module(). Currently it is opencoded in several places.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 3079c22e
...@@ -812,7 +812,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, ...@@ -812,7 +812,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
struct gendisk *disk; struct gendisk *disk;
struct request_queue *q; struct request_queue *q;
struct blkcg_gq *blkg; struct blkcg_gq *blkg;
struct module *owner;
unsigned int major, minor; unsigned int major, minor;
int key_len, part, ret; int key_len, part, ret;
char *body; char *body;
...@@ -904,9 +903,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, ...@@ -904,9 +903,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
spin_unlock_irq(q->queue_lock); spin_unlock_irq(q->queue_lock);
rcu_read_unlock(); rcu_read_unlock();
fail: fail:
owner = disk->fops->owner; put_disk_and_module(disk);
put_disk(disk);
module_put(owner);
/* /*
* If queue was bypassing, we should retry. Do so after a * If queue was bypassing, we should retry. Do so after a
* short msleep(). It isn't strictly necessary but queue * short msleep(). It isn't strictly necessary but queue
...@@ -931,13 +928,9 @@ EXPORT_SYMBOL_GPL(blkg_conf_prep); ...@@ -931,13 +928,9 @@ EXPORT_SYMBOL_GPL(blkg_conf_prep);
void blkg_conf_finish(struct blkg_conf_ctx *ctx) void blkg_conf_finish(struct blkg_conf_ctx *ctx)
__releases(ctx->disk->queue->queue_lock) __releases(rcu) __releases(ctx->disk->queue->queue_lock) __releases(rcu)
{ {
struct module *owner;
spin_unlock_irq(ctx->disk->queue->queue_lock); spin_unlock_irq(ctx->disk->queue->queue_lock);
rcu_read_unlock(); rcu_read_unlock();
owner = ctx->disk->fops->owner; put_disk_and_module(ctx->disk);
put_disk(ctx->disk);
module_put(owner);
} }
EXPORT_SYMBOL_GPL(blkg_conf_finish); EXPORT_SYMBOL_GPL(blkg_conf_finish);
......
...@@ -817,10 +817,7 @@ struct gendisk *get_gendisk(dev_t devt, int *partno) ...@@ -817,10 +817,7 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
} }
if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) { if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) {
struct module *owner = disk->fops->owner; put_disk_and_module(disk);
put_disk(disk);
module_put(owner);
disk = NULL; disk = NULL;
} }
return disk; return disk;
...@@ -1483,6 +1480,21 @@ void put_disk(struct gendisk *disk) ...@@ -1483,6 +1480,21 @@ void put_disk(struct gendisk *disk)
} }
EXPORT_SYMBOL(put_disk); EXPORT_SYMBOL(put_disk);
/*
* This is a counterpart of get_disk_and_module() and thus also of
* get_gendisk().
*/
void put_disk_and_module(struct gendisk *disk)
{
if (disk) {
struct module *owner = disk->fops->owner;
put_disk(disk);
module_put(owner);
}
}
EXPORT_SYMBOL(put_disk_and_module);
static void set_disk_ro_uevent(struct gendisk *gd, int ro) static void set_disk_ro_uevent(struct gendisk *gd, int ro)
{ {
char event[] = "DISK_RO=1"; char event[] = "DISK_RO=1";
......
...@@ -1111,8 +1111,7 @@ static struct block_device *bd_start_claiming(struct block_device *bdev, ...@@ -1111,8 +1111,7 @@ static struct block_device *bd_start_claiming(struct block_device *bdev,
else else
whole = bdgrab(bdev); whole = bdgrab(bdev);
module_put(disk->fops->owner); put_disk_and_module(disk);
put_disk(disk);
if (!whole) if (!whole)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -1407,7 +1406,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); ...@@ -1407,7 +1406,6 @@ static void __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) static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
{ {
struct gendisk *disk; struct gendisk *disk;
struct module *owner;
int ret; int ret;
int partno; int partno;
int perm = 0; int perm = 0;
...@@ -1433,7 +1431,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1433,7 +1431,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
disk = get_gendisk(bdev->bd_dev, &partno); disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk) if (!disk)
goto out; goto out;
owner = disk->fops->owner;
disk_block_events(disk); disk_block_events(disk);
mutex_lock_nested(&bdev->bd_mutex, for_part); mutex_lock_nested(&bdev->bd_mutex, for_part);
...@@ -1463,8 +1460,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1463,8 +1460,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
bdev->bd_queue = NULL; bdev->bd_queue = NULL;
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk); disk_unblock_events(disk);
put_disk(disk); put_disk_and_module(disk);
module_put(owner);
goto restart; goto restart;
} }
} }
...@@ -1525,8 +1521,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1525,8 +1521,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
goto out_unlock_bdev; goto out_unlock_bdev;
} }
/* only one opener holds refs to the module and disk */ /* only one opener holds refs to the module and disk */
put_disk(disk); put_disk_and_module(disk);
module_put(owner);
} }
bdev->bd_openers++; bdev->bd_openers++;
if (for_part) if (for_part)
...@@ -1546,8 +1541,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1546,8 +1541,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
out_unlock_bdev: out_unlock_bdev:
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk); disk_unblock_events(disk);
put_disk(disk); put_disk_and_module(disk);
module_put(owner);
out: out:
bdput(bdev); bdput(bdev);
...@@ -1770,8 +1764,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1770,8 +1764,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
disk->fops->release(disk, mode); disk->fops->release(disk, mode);
} }
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner;
disk_put_part(bdev->bd_part); disk_put_part(bdev->bd_part);
bdev->bd_part = NULL; bdev->bd_part = NULL;
bdev->bd_disk = NULL; bdev->bd_disk = NULL;
...@@ -1779,8 +1771,7 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1779,8 +1771,7 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
victim = bdev->bd_contains; victim = bdev->bd_contains;
bdev->bd_contains = NULL; bdev->bd_contains = NULL;
put_disk(disk); put_disk_and_module(disk);
module_put(owner);
} }
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
bdput(bdev); bdput(bdev);
......
...@@ -602,6 +602,7 @@ extern void printk_all_partitions(void); ...@@ -602,6 +602,7 @@ extern void printk_all_partitions(void);
extern struct gendisk *__alloc_disk_node(int minors, int node_id); extern struct gendisk *__alloc_disk_node(int minors, int node_id);
extern struct kobject *get_disk_and_module(struct gendisk *disk); extern struct kobject *get_disk_and_module(struct gendisk *disk);
extern void put_disk(struct gendisk *disk); extern void put_disk(struct gendisk *disk);
extern void put_disk_and_module(struct gendisk *disk);
extern void blk_register_region(dev_t devt, unsigned long range, extern void blk_register_region(dev_t devt, unsigned long range,
struct module *module, struct module *module,
struct kobject *(*probe)(dev_t, int *, void *), struct kobject *(*probe)(dev_t, int *, void *),
......
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