Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: remove (__)blkdev_reread_part as an exported API

In general drivers should never mess with partition tables directly.
Unfortunately s390 and loop do for somewhat historic reasons, but they
can use bdev_disk_changed directly instead when we export it as they
satisfy the sanity checks we have in __blkdev_reread_part.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com> [dasd]
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
f0b870df 142fe8f4

+23 -38
+5 -30
block/ioctl.c
··· 155 155 } 156 156 } 157 157 158 - /* 159 - * This is an exported API for the block driver, and will not 160 - * acquire bd_mutex. This API should be used in case that 161 - * caller has held bd_mutex already. 162 - */ 163 - int __blkdev_reread_part(struct block_device *bdev) 158 + static int blkdev_reread_part(struct block_device *bdev) 164 159 { 160 + int ret; 161 + 165 162 if (!disk_part_scan_enabled(bdev->bd_disk) || bdev != bdev->bd_contains) 166 163 return -EINVAL; 167 164 if (!capable(CAP_SYS_ADMIN)) 168 165 return -EACCES; 169 166 170 - lockdep_assert_held(&bdev->bd_mutex); 171 - 172 - return bdev_disk_changed(bdev, false); 173 - } 174 - EXPORT_SYMBOL(__blkdev_reread_part); 175 - 176 - /* 177 - * This is an exported API for the block driver, and will 178 - * try to acquire bd_mutex. If bd_mutex has been held already 179 - * in current context, please call __blkdev_reread_part(). 180 - * 181 - * Make sure the held locks in current context aren't required 182 - * in open()/close() handler and I/O path for avoiding ABBA deadlock: 183 - * - bd_mutex is held before calling block driver's open/close 184 - * handler 185 - * - reading partition table may submit I/O to the block device 186 - */ 187 - int blkdev_reread_part(struct block_device *bdev) 188 - { 189 - int res; 190 - 191 167 mutex_lock(&bdev->bd_mutex); 192 - res = __blkdev_reread_part(bdev); 168 + ret = bdev_disk_changed(bdev, false); 193 169 mutex_unlock(&bdev->bd_mutex); 194 170 195 - return res; 171 + return ret; 196 172 } 197 - EXPORT_SYMBOL(blkdev_reread_part); 198 173 199 174 static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, 200 175 unsigned long arg, unsigned long flags)
+8 -5
drivers/block/loop.c
··· 640 640 { 641 641 int rc; 642 642 643 - rc = blkdev_reread_part(bdev); 643 + mutex_lock(&bdev->bd_mutex); 644 + rc = bdev_disk_changed(bdev, false); 645 + mutex_unlock(&bdev->bd_mutex); 644 646 if (rc) 645 647 pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n", 646 648 __func__, lo->lo_number, lo->lo_file_name, rc); ··· 1166 1164 * must be at least one and it can only become zero when the 1167 1165 * current holder is released. 1168 1166 */ 1169 - if (release) 1170 - err = __blkdev_reread_part(bdev); 1171 - else 1172 - err = blkdev_reread_part(bdev); 1167 + if (!release) 1168 + mutex_lock(&bdev->bd_mutex); 1169 + err = bdev_disk_changed(bdev, false); 1170 + if (!release) 1171 + mutex_unlock(&bdev->bd_mutex); 1173 1172 if (err) 1174 1173 pr_warn("%s: partition scan of loop%d failed (rc=%d)\n", 1175 1174 __func__, lo_number, err);
+3 -1
drivers/s390/block/dasd_genhd.c
··· 116 116 return -ENODEV; 117 117 } 118 118 119 - rc = blkdev_reread_part(bdev); 119 + mutex_lock(&bdev->bd_mutex); 120 + rc = bdev_disk_changed(bdev, false); 121 + mutex_unlock(&bdev->bd_mutex); 120 122 if (rc) 121 123 DBF_DEV_EVENT(DBF_ERR, block->base, 122 124 "scan partitions error, rc %d", rc);
+7
fs/block_dev.c
··· 1513 1513 struct gendisk *disk = bdev->bd_disk; 1514 1514 int ret; 1515 1515 1516 + lockdep_assert_held(&bdev->bd_mutex); 1517 + 1516 1518 rescan: 1517 1519 ret = blk_drop_partitions(disk, bdev); 1518 1520 if (ret) ··· 1542 1540 1543 1541 return ret; 1544 1542 } 1543 + /* 1544 + * Only exported for for loop and dasd for historic reasons. Don't use in new 1545 + * code! 1546 + */ 1547 + EXPORT_SYMBOL_GPL(bdev_disk_changed); 1545 1548 1546 1549 /* 1547 1550 * bd_mutex locking:
-2
include/linux/fs.h
··· 2632 2632 extern void bd_abort_claiming(struct block_device *bdev, 2633 2633 struct block_device *whole, void *holder); 2634 2634 extern void blkdev_put(struct block_device *bdev, fmode_t mode); 2635 - extern int __blkdev_reread_part(struct block_device *bdev); 2636 - extern int blkdev_reread_part(struct block_device *bdev); 2637 2635 2638 2636 #ifdef CONFIG_SYSFS 2639 2637 extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);