Skip to content

Commit

Permalink
block: Add invalidate_disk() helper to invalidate the gendisk
Browse files Browse the repository at this point in the history
To hide internal implementation and simplify some driver code,
this adds a helper to invalidate the gendisk. It will clean the
gendisk's associated buffer/page caches and reset its internal
states.

Signed-off-by: Xie Yongji <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
YongjiXie authored and axboe committed Oct 21, 2021
1 parent e94f685 commit f059a1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,26 @@ void del_gendisk(struct gendisk *disk)
}
EXPORT_SYMBOL(del_gendisk);

/**
* invalidate_disk - invalidate the disk
* @disk: the struct gendisk to invalidate
*
* A helper to invalidates the disk. It will clean the disk's associated
* buffer/page caches and reset its internal states so that the disk
* can be reused by the drivers.
*
* Context: can sleep
*/
void invalidate_disk(struct gendisk *disk)
{
struct block_device *bdev = disk->part0;

invalidate_bdev(bdev);
bdev->bd_inode->i_mapping->wb_err = 0;
set_capacity(disk, 0);
}
EXPORT_SYMBOL(invalidate_disk);

/* sysfs access to bad-blocks list. */
static ssize_t disk_badblocks_show(struct device *dev,
struct device_attribute *attr,
Expand Down
2 changes: 2 additions & 0 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ static inline int add_disk(struct gendisk *disk)
}
extern void del_gendisk(struct gendisk *gp);

void invalidate_disk(struct gendisk *disk);

void set_disk_ro(struct gendisk *disk, bool read_only);

static inline int get_disk_ro(struct gendisk *disk)
Expand Down

0 comments on commit f059a1d

Please sign in to comment.