Skip to content

Commit 6e57236

Browse files
Christoph Hellwigbrauner
authored andcommitted
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>
1 parent 51b4cb4 commit 6e57236

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

block/bdev.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,14 +1019,13 @@ void bdev_mark_dead(struct block_device *bdev, bool surprise)
10191019

10201020
invalidate_bdev(bdev);
10211021
}
1022-
#ifdef CONFIG_DASD_MODULE
10231022
/*
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.
10271027
*/
10281028
EXPORT_SYMBOL_GPL(bdev_mark_dead);
1029-
#endif
10301029

10311030
void sync_bdevs(bool wait)
10321031
{

block/disk-events.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,24 +266,20 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
266266
* disk_check_media_change - check if a removable media has been changed
267267
* @disk: gendisk to check
268268
*
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.
274271
*/
275272
bool disk_check_media_change(struct gendisk *disk)
276273
{
277274
unsigned int events;
278275

279276
events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
280277
DISK_EVENT_EJECT_REQUEST);
281-
if (!(events & DISK_EVENT_MEDIA_CHANGE))
282-
return false;
283-
284-
bdev_mark_dead(disk->part0, true);
285-
set_bit(GD_NEED_PART_SCAN, &disk->state);
286-
return true;
278+
if (events & DISK_EVENT_MEDIA_CHANGE) {
279+
set_bit(GD_NEED_PART_SCAN, &disk->state);
280+
return true;
281+
}
282+
return false;
287283
}
288284
EXPORT_SYMBOL(disk_check_media_change);
289285

drivers/block/ataflop.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,8 +1760,10 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
17601760
/* invalidate the buffer track to force a reread */
17611761
BufferDrive = -1;
17621762
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);
17641765
floppy_revalidate(disk);
1766+
}
17651767
return 0;
17661768
default:
17671769
return -EINVAL;

drivers/block/floppy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3215,8 +3215,10 @@ static int invalidate_drive(struct gendisk *disk)
32153215
/* invalidate the buffer track to force a reread */
32163216
set_bit((long)disk->private_data, &fake_change);
32173217
process_fd_request();
3218-
if (disk_check_media_change(disk))
3218+
if (disk_check_media_change(disk)) {
3219+
bdev_mark_dead(disk->part0, true);
32193220
floppy_revalidate(disk);
3221+
}
32203222
return 0;
32213223
}
32223224

0 commit comments

Comments
 (0)