Commit 95f6f3a4 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: add a bdev_check_media_change helper

Like check_disk_changed, except that it does not call ->revalidate_disk
but leaves that to the caller.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent fc93fe14
...@@ -2052,7 +2052,7 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask) ...@@ -2052,7 +2052,7 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask)
* CONTEXT: * CONTEXT:
* Might sleep. * Might sleep.
*/ */
unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask) static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
{ {
struct disk_events *ev = disk->ev; struct disk_events *ev = disk->ev;
unsigned int pending; unsigned int pending;
...@@ -2090,6 +2090,33 @@ unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask) ...@@ -2090,6 +2090,33 @@ unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)
return pending; return pending;
} }
/**
* bdev_check_media_change - check if a removable media has been changed
* @bdev: block device 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.
*/
bool bdev_check_media_change(struct block_device *bdev)
{
unsigned int events;
events = disk_clear_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE |
DISK_EVENT_EJECT_REQUEST);
if (!(events & DISK_EVENT_MEDIA_CHANGE))
return false;
if (__invalidate_device(bdev, true))
pr_warn("VFS: busy inodes on changed media %s\n",
bdev->bd_disk->disk_name);
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags);
return true;
}
EXPORT_SYMBOL(bdev_check_media_change);
/* /*
* Separate this part out so that a different pointer for clearing_ptr can be * Separate this part out so that a different pointer for clearing_ptr can be
* passed in for disk_clear_events. * passed in for disk_clear_events.
......
...@@ -1379,21 +1379,10 @@ EXPORT_SYMBOL(revalidate_disk_size); ...@@ -1379,21 +1379,10 @@ EXPORT_SYMBOL(revalidate_disk_size);
*/ */
int check_disk_change(struct block_device *bdev) int check_disk_change(struct block_device *bdev)
{ {
struct gendisk *disk = bdev->bd_disk; if (!bdev_check_media_change(bdev))
const struct block_device_operations *bdops = disk->fops;
unsigned int events;
events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
DISK_EVENT_EJECT_REQUEST);
if (!(events & DISK_EVENT_MEDIA_CHANGE))
return 0; return 0;
if (bdev->bd_disk->fops->revalidate_disk)
if (__invalidate_device(bdev, true)) bdev->bd_disk->fops->revalidate_disk(bdev->bd_disk);
pr_warn("VFS: busy inodes on changed media %s\n",
disk->disk_name);
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags);
if (bdops->revalidate_disk)
bdops->revalidate_disk(bdev->bd_disk);
return 1; return 1;
} }
......
...@@ -315,7 +315,6 @@ extern void disk_unblock_events(struct gendisk *disk); ...@@ -315,7 +315,6 @@ extern void disk_unblock_events(struct gendisk *disk);
extern void disk_flush_events(struct gendisk *disk, unsigned int mask); extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
bool update_bdev); bool update_bdev);
extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
/* drivers/char/random.c */ /* drivers/char/random.c */
extern void add_disk_randomness(struct gendisk *disk) __latent_entropy; extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
...@@ -372,6 +371,7 @@ void unregister_blkdev(unsigned int major, const char *name); ...@@ -372,6 +371,7 @@ void unregister_blkdev(unsigned int major, const char *name);
void revalidate_disk_size(struct gendisk *disk, bool verbose); void revalidate_disk_size(struct gendisk *disk, bool verbose);
int check_disk_change(struct block_device *bdev); int check_disk_change(struct block_device *bdev);
bool bdev_check_media_change(struct block_device *bdev);
int __invalidate_device(struct block_device *bdev, bool kill_dirty); int __invalidate_device(struct block_device *bdev, bool kill_dirty);
void bd_set_nr_sectors(struct block_device *bdev, sector_t sectors); void bd_set_nr_sectors(struct block_device *bdev, sector_t sectors);
......
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