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

block: move bdev_mark_dead out of disk_check_media_change

disk_check_media_change is mostly called from ->open where it makes
little sense to mark the file system on the device as dead, as we
are just opening it. So instead of calling bdev_mark_dead from
disk_check_media_change move it into the few callers that are not
in an open instance. This avoid calling into bdev_mark_dead and
thus taking s_umount with open_mutex held.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20231017184823.1383356-4-hch@lst.de
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Christoph Hellwig and committed by
Christian Brauner
6e57236e 51b4cb4f

+17 -18
+4 -5
block/bdev.c
··· 1019 1019 1020 1020 invalidate_bdev(bdev); 1021 1021 } 1022 - #ifdef CONFIG_DASD_MODULE 1023 1022 /* 1024 - * Drivers should not use this directly, but the DASD driver has historically 1025 - * had a shutdown to offline mode that doesn't actually remove the gendisk 1026 - * that otherwise looks a lot like a safe device removal. 1023 + * New drivers should not use this directly. There are some drivers however 1024 + * that needs this for historical reasons. For example, the DASD driver has 1025 + * historically had a shutdown to offline mode that doesn't actually remove the 1026 + * gendisk that otherwise looks a lot like a safe device removal. 1027 1027 */ 1028 1028 EXPORT_SYMBOL_GPL(bdev_mark_dead); 1029 - #endif 1030 1029 1031 1030 void sync_bdevs(bool wait) 1032 1031 {
+7 -11
block/disk-events.c
··· 266 266 * disk_check_media_change - check if a removable media has been changed 267 267 * @disk: gendisk to check 268 268 * 269 - * Check whether a removable media has been changed, and attempt to free all 270 - * dentries and inodes and invalidates all block device page cache entries in 271 - * that case. 272 - * 273 - * Returns %true if the media has changed, or %false if not. 269 + * Returns %true and marks the disk for a partition rescan whether a removable 270 + * media has been changed, and %false if the media did not change. 274 271 */ 275 272 bool disk_check_media_change(struct gendisk *disk) 276 273 { ··· 275 278 276 279 events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE | 277 280 DISK_EVENT_EJECT_REQUEST); 278 - if (!(events & DISK_EVENT_MEDIA_CHANGE)) 279 - return false; 280 - 281 - bdev_mark_dead(disk->part0, true); 282 - set_bit(GD_NEED_PART_SCAN, &disk->state); 283 - return true; 281 + if (events & DISK_EVENT_MEDIA_CHANGE) { 282 + set_bit(GD_NEED_PART_SCAN, &disk->state); 283 + return true; 284 + } 285 + return false; 284 286 } 285 287 EXPORT_SYMBOL(disk_check_media_change); 286 288
+3 -1
drivers/block/ataflop.c
··· 1760 1760 /* invalidate the buffer track to force a reread */ 1761 1761 BufferDrive = -1; 1762 1762 set_bit(drive, &fake_change); 1763 - if (disk_check_media_change(disk)) 1763 + if (disk_check_media_change(disk)) { 1764 + bdev_mark_dead(disk->part0, true); 1764 1765 floppy_revalidate(disk); 1766 + } 1765 1767 return 0; 1766 1768 default: 1767 1769 return -EINVAL;
+3 -1
drivers/block/floppy.c
··· 3215 3215 /* invalidate the buffer track to force a reread */ 3216 3216 set_bit((long)disk->private_data, &fake_change); 3217 3217 process_fd_request(); 3218 - if (disk_check_media_change(disk)) 3218 + if (disk_check_media_change(disk)) { 3219 + bdev_mark_dead(disk->part0, true); 3219 3220 floppy_revalidate(disk); 3221 + } 3220 3222 return 0; 3221 3223 } 3222 3224