Skip to content

Commit

Permalink
block: export blkdev_reread_part() and __blkdev_reread_part()
Browse files Browse the repository at this point in the history
This patch exports blkdev_reread_part() for block drivers, also
introduce __blkdev_reread_part().

For some drivers, such as loop, reread of partitions can be run
from the release path, and bd_mutex may already be held prior to
calling ioctl_by_bdev(bdev, BLKRRPART, 0), so introduce
__blkdev_reread_part for use in such cases.

CC: Christoph Hellwig <[email protected]>
CC: Jens Axboe <[email protected]>
CC: Tejun Heo <[email protected]>
CC: Alexander Viro <[email protected]>
CC: Markus Pargmann <[email protected]>
CC: Stefan Weinhuber <[email protected]>
CC: Stefan Haberland <[email protected]>
CC: Sebastian Ott <[email protected]>
CC: Fabian Frederick <[email protected]>
CC: Ming Lei <[email protected]>
CC: David Herrmann <[email protected]>
CC: Andrew Morton <[email protected]>
CC: Peter Zijlstra <[email protected]>
CC: [email protected]
CC: [email protected]
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jarod Wilson <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
jarodwilson authored and axboe committed May 20, 2015
1 parent 343df3c commit be32417
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 25 additions & 3 deletions block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,43 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
}
}

static int blkdev_reread_part(struct block_device *bdev)
/*
* This is an exported API for the block driver, and will not
* acquire bd_mutex. This API should be used in case that
* caller has held bd_mutex already.
*/
int __blkdev_reread_part(struct block_device *bdev)
{
struct gendisk *disk = bdev->bd_disk;
int res;

if (!disk_part_scan_enabled(disk) || bdev != bdev->bd_contains)
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;

lockdep_assert_held(&bdev->bd_mutex);

return rescan_partitions(disk, bdev);
}
EXPORT_SYMBOL(__blkdev_reread_part);

/*
* This is an exported API for the block driver, and will
* try to acquire bd_mutex. If bd_mutex has been held already
* in current context, please call __blkdev_reread_part().
*/
int blkdev_reread_part(struct block_device *bdev)
{
int res;

if (!mutex_trylock(&bdev->bd_mutex))
return -EBUSY;
res = rescan_partitions(disk, bdev);
res = __blkdev_reread_part(bdev);
mutex_unlock(&bdev->bd_mutex);

return res;
}
EXPORT_SYMBOL(blkdev_reread_part);

static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
uint64_t len, int secure)
Expand Down
3 changes: 3 additions & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,9 @@ extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
void *holder);
extern void blkdev_put(struct block_device *bdev, fmode_t mode);
extern int __blkdev_reread_part(struct block_device *bdev);
extern int blkdev_reread_part(struct block_device *bdev);

#ifdef CONFIG_SYSFS
extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
extern void bd_unlink_disk_holder(struct block_device *bdev,
Expand Down

0 comments on commit be32417

Please sign in to comment.