Commit 444aa2c5 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: pass a gendisk on bdev_check_media_change

bdev_check_media_change should only ever be called for the whole device.
Pass a gendisk to make that explicit and rename the function to
disk_check_media_change.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20230608110258.189493-8-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7ae24fce
...@@ -263,31 +263,31 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask) ...@@ -263,31 +263,31 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
} }
/** /**
* bdev_check_media_change - check if a removable media has been changed * disk_check_media_change - check if a removable media has been changed
* @bdev: block device to check * @disk: gendisk to check
* *
* Check whether a removable media has been changed, and attempt to free all * Check whether a removable media has been changed, and attempt to free all
* dentries and inodes and invalidates all block device page cache entries in * dentries and inodes and invalidates all block device page cache entries in
* that case. * that case.
* *
* Returns %true if the block device changed, or %false if not. * Returns %true if the media has changed, or %false if not.
*/ */
bool bdev_check_media_change(struct block_device *bdev) bool disk_check_media_change(struct gendisk *disk)
{ {
unsigned int events; unsigned int events;
events = disk_clear_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE | events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
DISK_EVENT_EJECT_REQUEST); DISK_EVENT_EJECT_REQUEST);
if (!(events & DISK_EVENT_MEDIA_CHANGE)) if (!(events & DISK_EVENT_MEDIA_CHANGE))
return false; return false;
if (__invalidate_device(bdev, true)) if (__invalidate_device(disk->part0, true))
pr_warn("VFS: busy inodes on changed media %s\n", pr_warn("VFS: busy inodes on changed media %s\n",
bdev->bd_disk->disk_name); disk->disk_name);
set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state); set_bit(GD_NEED_PART_SCAN, &disk->state);
return true; return true;
} }
EXPORT_SYMBOL(bdev_check_media_change); EXPORT_SYMBOL(disk_check_media_change);
/** /**
* disk_force_media_change - force a media change event * disk_force_media_change - force a media change event
......
...@@ -1675,7 +1675,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -1675,7 +1675,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
} }
if (mode & (FMODE_READ|FMODE_WRITE)) { if (mode & (FMODE_READ|FMODE_WRITE)) {
bdev_check_media_change(bdev); disk_check_media_change(bdev->bd_disk);
if (mode & FMODE_WRITE) { if (mode & FMODE_WRITE) {
int wrprot; int wrprot;
......
...@@ -1760,8 +1760,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -1760,8 +1760,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,
/* invalidate the buffer track to force a reread */ /* invalidate the buffer track to force a reread */
BufferDrive = -1; BufferDrive = -1;
set_bit(drive, &fake_change); set_bit(drive, &fake_change);
if (bdev_check_media_change(bdev)) if (disk_check_media_change(disk))
floppy_revalidate(bdev->bd_disk); floppy_revalidate(disk);
return 0; return 0;
default: default:
return -EINVAL; return -EINVAL;
...@@ -1938,7 +1938,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -1938,7 +1938,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
return 0; return 0;
if (mode & (FMODE_READ|FMODE_WRITE)) { if (mode & (FMODE_READ|FMODE_WRITE)) {
if (bdev_check_media_change(bdev)) if (disk_check_media_change(bdev->bd_disk))
floppy_revalidate(bdev->bd_disk); floppy_revalidate(bdev->bd_disk);
if (mode & FMODE_WRITE) { if (mode & FMODE_WRITE) {
if (p->wpstat) { if (p->wpstat) {
......
...@@ -3210,13 +3210,13 @@ static int floppy_raw_cmd_ioctl(int type, int drive, int cmd, ...@@ -3210,13 +3210,13 @@ static int floppy_raw_cmd_ioctl(int type, int drive, int cmd,
#endif #endif
static int invalidate_drive(struct block_device *bdev) static int invalidate_drive(struct gendisk *disk)
{ {
/* invalidate the buffer track to force a reread */ /* invalidate the buffer track to force a reread */
set_bit((long)bdev->bd_disk->private_data, &fake_change); set_bit((long)disk->private_data, &fake_change);
process_fd_request(); process_fd_request();
if (bdev_check_media_change(bdev)) if (disk_check_media_change(disk))
floppy_revalidate(bdev->bd_disk); floppy_revalidate(disk);
return 0; return 0;
} }
...@@ -3287,7 +3287,7 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g, ...@@ -3287,7 +3287,7 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
drive_state[current_drive].maxtrack || drive_state[current_drive].maxtrack ||
((user_params[drive].sect ^ oldStretch) & ((user_params[drive].sect ^ oldStretch) &
(FD_SWAPSIDES | FD_SECTBASEMASK))) (FD_SWAPSIDES | FD_SECTBASEMASK)))
invalidate_drive(bdev); invalidate_drive(bdev->bd_disk);
else else
process_fd_request(); process_fd_request();
} }
...@@ -3464,7 +3464,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int ...@@ -3464,7 +3464,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
current_type[drive] = NULL; current_type[drive] = NULL;
floppy_sizes[drive] = MAX_DISK_SIZE << 1; floppy_sizes[drive] = MAX_DISK_SIZE << 1;
drive_state[drive].keep_data = 0; drive_state[drive].keep_data = 0;
return invalidate_drive(bdev); return invalidate_drive(bdev->bd_disk);
case FDSETPRM: case FDSETPRM:
case FDDEFPRM: case FDDEFPRM:
return set_geometry(cmd, &inparam.g, drive, type, bdev); return set_geometry(cmd, &inparam.g, drive, type, bdev);
...@@ -3503,7 +3503,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int ...@@ -3503,7 +3503,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
case FDFLUSH: case FDFLUSH:
if (lock_fdc(drive)) if (lock_fdc(drive))
return -EINTR; return -EINTR;
return invalidate_drive(bdev); return invalidate_drive(bdev->bd_disk);
case FDSETEMSGTRESH: case FDSETEMSGTRESH:
drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f); drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
return 0; return 0;
...@@ -4054,7 +4054,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -4054,7 +4054,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
drive_state[drive].last_checked = 0; drive_state[drive].last_checked = 0;
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
&drive_state[drive].flags); &drive_state[drive].flags);
if (bdev_check_media_change(bdev)) if (disk_check_media_change(bdev->bd_disk))
floppy_revalidate(bdev->bd_disk); floppy_revalidate(bdev->bd_disk);
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags)) if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
goto out; goto out;
......
...@@ -640,7 +640,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -640,7 +640,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
return 0; return 0;
if (mode & (FMODE_READ|FMODE_WRITE)) { if (mode & (FMODE_READ|FMODE_WRITE)) {
if (bdev_check_media_change(bdev) && fs->disk_in) if (disk_check_media_change(bdev->bd_disk) && fs->disk_in)
fs->ejected = 0; fs->ejected = 0;
if ((mode & FMODE_WRITE) && fs->write_protected) { if ((mode & FMODE_WRITE) && fs->write_protected) {
err = -EROFS; err = -EROFS;
......
...@@ -963,7 +963,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -963,7 +963,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
if (err == 0 && (mode & FMODE_NDELAY) == 0 if (err == 0 && (mode & FMODE_NDELAY) == 0
&& (mode & (FMODE_READ|FMODE_WRITE))) { && (mode & (FMODE_READ|FMODE_WRITE))) {
if (bdev_check_media_change(bdev)) if (disk_check_media_change(bdev->bd_disk))
floppy_revalidate(bdev->bd_disk); floppy_revalidate(bdev->bd_disk);
if (fs->ejected) if (fs->ejected)
err = -ENXIO; err = -ENXIO;
......
...@@ -478,7 +478,7 @@ static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode) ...@@ -478,7 +478,7 @@ static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
{ {
int ret; int ret;
bdev_check_media_change(bdev); disk_check_media_change(bdev->bd_disk);
mutex_lock(&gdrom_mutex); mutex_lock(&gdrom_mutex);
ret = cdrom_open(gd.cd_info); ret = cdrom_open(gd.cd_info);
......
...@@ -7789,7 +7789,7 @@ static int md_open(struct block_device *bdev, fmode_t mode) ...@@ -7789,7 +7789,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
atomic_inc(&mddev->openers); atomic_inc(&mddev->openers);
mutex_unlock(&mddev->open_mutex); mutex_unlock(&mddev->open_mutex);
bdev_check_media_change(bdev); disk_check_media_change(bdev->bd_disk);
return 0; return 0;
out_unlock: out_unlock:
......
...@@ -1280,11 +1280,10 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt) ...@@ -1280,11 +1280,10 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt)
mempool_free(rq->special_vec.bv_page, sd_page_pool); mempool_free(rq->special_vec.bv_page, sd_page_pool);
} }
static bool sd_need_revalidate(struct block_device *bdev, static bool sd_need_revalidate(struct gendisk *disk, struct scsi_disk *sdkp)
struct scsi_disk *sdkp)
{ {
if (sdkp->device->removable || sdkp->write_prot) { if (sdkp->device->removable || sdkp->write_prot) {
if (bdev_check_media_change(bdev)) if (disk_check_media_change(disk))
return true; return true;
} }
...@@ -1293,7 +1292,7 @@ static bool sd_need_revalidate(struct block_device *bdev, ...@@ -1293,7 +1292,7 @@ static bool sd_need_revalidate(struct block_device *bdev,
* nothing to do with partitions, BLKRRPART is used to force a full * nothing to do with partitions, BLKRRPART is used to force a full
* revalidate after things like a format for historical reasons. * revalidate after things like a format for historical reasons.
*/ */
return test_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state); return test_bit(GD_NEED_PART_SCAN, &disk->state);
} }
/** /**
...@@ -1330,7 +1329,7 @@ static int sd_open(struct block_device *bdev, fmode_t mode) ...@@ -1330,7 +1329,7 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
if (!scsi_block_when_processing_errors(sdev)) if (!scsi_block_when_processing_errors(sdev))
goto error_out; goto error_out;
if (sd_need_revalidate(bdev, sdkp)) if (sd_need_revalidate(bdev->bd_disk, sdkp))
sd_revalidate_disk(bdev->bd_disk); sd_revalidate_disk(bdev->bd_disk);
/* /*
......
...@@ -494,7 +494,7 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode) ...@@ -494,7 +494,7 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)
return -ENXIO; return -ENXIO;
scsi_autopm_get_device(sdev); scsi_autopm_get_device(sdev);
if (bdev_check_media_change(bdev)) if (disk_check_media_change(bdev->bd_disk))
sr_revalidate_disk(cd); sr_revalidate_disk(cd);
mutex_lock(&cd->lock); mutex_lock(&cd->lock);
......
...@@ -817,7 +817,7 @@ int __register_blkdev(unsigned int major, const char *name, ...@@ -817,7 +817,7 @@ int __register_blkdev(unsigned int major, const char *name,
__register_blkdev(major, name, NULL) __register_blkdev(major, name, NULL)
void unregister_blkdev(unsigned int major, const char *name); void unregister_blkdev(unsigned int major, const char *name);
bool bdev_check_media_change(struct block_device *bdev); bool disk_check_media_change(struct gendisk *disk);
int __invalidate_device(struct block_device *bdev, bool kill_dirty); int __invalidate_device(struct block_device *bdev, bool kill_dirty);
void set_capacity(struct gendisk *disk, sector_t size); void set_capacity(struct gendisk *disk, sector_t size);
......
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