mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
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: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Acked-by: Christian Brauner <brauner@kernel.org> Link: https://lore.kernel.org/r/20230608110258.189493-8-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
7ae24fcee9
commit
444aa2c58c
@ -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
|
||||
* @bdev: block device to check
|
||||
* disk_check_media_change - check if a removable media has been changed
|
||||
* @disk: gendisk to check
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
|
||||
events = disk_clear_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE |
|
||||
events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
|
||||
DISK_EVENT_EJECT_REQUEST);
|
||||
if (!(events & DISK_EVENT_MEDIA_CHANGE))
|
||||
return false;
|
||||
|
||||
if (__invalidate_device(bdev, true))
|
||||
if (__invalidate_device(disk->part0, true))
|
||||
pr_warn("VFS: busy inodes on changed media %s\n",
|
||||
bdev->bd_disk->disk_name);
|
||||
set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
|
||||
disk->disk_name);
|
||||
set_bit(GD_NEED_PART_SCAN, &disk->state);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(bdev_check_media_change);
|
||||
EXPORT_SYMBOL(disk_check_media_change);
|
||||
|
||||
/**
|
||||
* disk_force_media_change - force a media change event
|
||||
|
@ -1675,7 +1675,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
|
||||
}
|
||||
|
||||
if (mode & (FMODE_READ|FMODE_WRITE)) {
|
||||
bdev_check_media_change(bdev);
|
||||
disk_check_media_change(bdev->bd_disk);
|
||||
if (mode & FMODE_WRITE) {
|
||||
int wrprot;
|
||||
|
||||
|
@ -1760,8 +1760,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,
|
||||
/* invalidate the buffer track to force a reread */
|
||||
BufferDrive = -1;
|
||||
set_bit(drive, &fake_change);
|
||||
if (bdev_check_media_change(bdev))
|
||||
floppy_revalidate(bdev->bd_disk);
|
||||
if (disk_check_media_change(disk))
|
||||
floppy_revalidate(disk);
|
||||
return 0;
|
||||
default:
|
||||
return -EINVAL;
|
||||
@ -1938,7 +1938,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
|
||||
return 0;
|
||||
|
||||
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);
|
||||
if (mode & FMODE_WRITE) {
|
||||
if (p->wpstat) {
|
||||
|
@ -3210,13 +3210,13 @@ static int floppy_raw_cmd_ioctl(int type, int drive, int cmd,
|
||||
|
||||
#endif
|
||||
|
||||
static int invalidate_drive(struct block_device *bdev)
|
||||
static int invalidate_drive(struct gendisk *disk)
|
||||
{
|
||||
/* 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();
|
||||
if (bdev_check_media_change(bdev))
|
||||
floppy_revalidate(bdev->bd_disk);
|
||||
if (disk_check_media_change(disk))
|
||||
floppy_revalidate(disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3287,7 +3287,7 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
|
||||
drive_state[current_drive].maxtrack ||
|
||||
((user_params[drive].sect ^ oldStretch) &
|
||||
(FD_SWAPSIDES | FD_SECTBASEMASK)))
|
||||
invalidate_drive(bdev);
|
||||
invalidate_drive(bdev->bd_disk);
|
||||
else
|
||||
process_fd_request();
|
||||
}
|
||||
@ -3464,7 +3464,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
|
||||
current_type[drive] = NULL;
|
||||
floppy_sizes[drive] = MAX_DISK_SIZE << 1;
|
||||
drive_state[drive].keep_data = 0;
|
||||
return invalidate_drive(bdev);
|
||||
return invalidate_drive(bdev->bd_disk);
|
||||
case FDSETPRM:
|
||||
case FDDEFPRM:
|
||||
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
|
||||
case FDFLUSH:
|
||||
if (lock_fdc(drive))
|
||||
return -EINTR;
|
||||
return invalidate_drive(bdev);
|
||||
return invalidate_drive(bdev->bd_disk);
|
||||
case FDSETEMSGTRESH:
|
||||
drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
|
||||
return 0;
|
||||
@ -4054,7 +4054,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
|
||||
drive_state[drive].last_checked = 0;
|
||||
clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
|
||||
&drive_state[drive].flags);
|
||||
if (bdev_check_media_change(bdev))
|
||||
if (disk_check_media_change(bdev->bd_disk))
|
||||
floppy_revalidate(bdev->bd_disk);
|
||||
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
|
||||
goto out;
|
||||
|
@ -640,7 +640,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
|
||||
return 0;
|
||||
|
||||
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;
|
||||
if ((mode & FMODE_WRITE) && fs->write_protected) {
|
||||
err = -EROFS;
|
||||
|
@ -963,7 +963,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
|
||||
|
||||
if (err == 0 && (mode & FMODE_NDELAY) == 0
|
||||
&& (mode & (FMODE_READ|FMODE_WRITE))) {
|
||||
if (bdev_check_media_change(bdev))
|
||||
if (disk_check_media_change(bdev->bd_disk))
|
||||
floppy_revalidate(bdev->bd_disk);
|
||||
if (fs->ejected)
|
||||
err = -ENXIO;
|
||||
|
@ -478,7 +478,7 @@ static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bdev_check_media_change(bdev);
|
||||
disk_check_media_change(bdev->bd_disk);
|
||||
|
||||
mutex_lock(&gdrom_mutex);
|
||||
ret = cdrom_open(gd.cd_info);
|
||||
|
@ -7789,7 +7789,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
|
||||
atomic_inc(&mddev->openers);
|
||||
mutex_unlock(&mddev->open_mutex);
|
||||
|
||||
bdev_check_media_change(bdev);
|
||||
disk_check_media_change(bdev->bd_disk);
|
||||
return 0;
|
||||
|
||||
out_unlock:
|
||||
|
@ -1280,11 +1280,10 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt)
|
||||
mempool_free(rq->special_vec.bv_page, sd_page_pool);
|
||||
}
|
||||
|
||||
static bool sd_need_revalidate(struct block_device *bdev,
|
||||
struct scsi_disk *sdkp)
|
||||
static bool sd_need_revalidate(struct gendisk *disk, struct scsi_disk *sdkp)
|
||||
{
|
||||
if (sdkp->device->removable || sdkp->write_prot) {
|
||||
if (bdev_check_media_change(bdev))
|
||||
if (disk_check_media_change(disk))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -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
|
||||
* 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)
|
||||
if (!scsi_block_when_processing_errors(sdev))
|
||||
goto error_out;
|
||||
|
||||
if (sd_need_revalidate(bdev, sdkp))
|
||||
if (sd_need_revalidate(bdev->bd_disk, sdkp))
|
||||
sd_revalidate_disk(bdev->bd_disk);
|
||||
|
||||
/*
|
||||
|
@ -494,7 +494,7 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)
|
||||
return -ENXIO;
|
||||
|
||||
scsi_autopm_get_device(sdev);
|
||||
if (bdev_check_media_change(bdev))
|
||||
if (disk_check_media_change(bdev->bd_disk))
|
||||
sr_revalidate_disk(cd);
|
||||
|
||||
mutex_lock(&cd->lock);
|
||||
|
@ -817,7 +817,7 @@ int __register_blkdev(unsigned int major, const char *name,
|
||||
__register_blkdev(major, name, NULL)
|
||||
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);
|
||||
void set_capacity(struct gendisk *disk, sector_t size);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user