summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorXie Yongji <xieyongji@bytedance.com>2021-09-22 20:37:08 +0800
committerJens Axboe <axboe@kernel.dk>2021-10-21 10:12:41 -0600
commitf059a1d2e23a165bf86e33673c6a7535a08c6341 (patch)
treec009d3e5c96d7848902627704c613bb324156dd4 /block
parente94f68527a35271131cdf9d3fb4eb3c2513dc3d0 (diff)
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 <xieyongji@bytedance.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210922123711.187-2-xieyongji@bytedance.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/genhd.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 80943c123c3e..64f83c4aee99 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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,