Skip to content

Commit f059a1d

Browse files
YongjiXieaxboe
authored andcommitted
block: Add invalidate_disk() helper to invalidate the gendisk
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]>
1 parent e94f685 commit f059a1d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

block/genhd.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,26 @@ void del_gendisk(struct gendisk *disk)
624624
}
625625
EXPORT_SYMBOL(del_gendisk);
626626

627+
/**
628+
* invalidate_disk - invalidate the disk
629+
* @disk: the struct gendisk to invalidate
630+
*
631+
* A helper to invalidates the disk. It will clean the disk's associated
632+
* buffer/page caches and reset its internal states so that the disk
633+
* can be reused by the drivers.
634+
*
635+
* Context: can sleep
636+
*/
637+
void invalidate_disk(struct gendisk *disk)
638+
{
639+
struct block_device *bdev = disk->part0;
640+
641+
invalidate_bdev(bdev);
642+
bdev->bd_inode->i_mapping->wb_err = 0;
643+
set_capacity(disk, 0);
644+
}
645+
EXPORT_SYMBOL(invalidate_disk);
646+
627647
/* sysfs access to bad-blocks list. */
628648
static ssize_t disk_badblocks_show(struct device *dev,
629649
struct device_attribute *attr,

include/linux/genhd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ static inline int add_disk(struct gendisk *disk)
213213
}
214214
extern void del_gendisk(struct gendisk *gp);
215215

216+
void invalidate_disk(struct gendisk *disk);
217+
216218
void set_disk_ro(struct gendisk *disk, bool read_only);
217219

218220
static inline int get_disk_ro(struct gendisk *disk)

0 commit comments

Comments
 (0)