diff mbox series

block: warn when write a bdev which already mounted

Message ID 20230822093954.6991-1-changfengnan@bytedance.com (mailing list archive)
State New, archived
Headers show
Series block: warn when write a bdev which already mounted | expand

Commit Message

Fengnan Chang Aug. 22, 2023, 9:39 a.m. UTC
we may write a bdev which already mounted by
accidentally, and cause filesystem corrupt, add
a warn log to notice user.

Signed-off-by: Fengnan Chang <changfengnan@bytedance.com>
---
 block/fops.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/block/fops.c b/block/fops.c
index a286bf3325c5..5b679ad48df4 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -563,6 +563,11 @@  static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) == IOCB_NOWAIT)
 		return -EOPNOTSUPP;
 
+	if (bdev->bd_super)
+		pr_warn_once("warn:try write bdev %s, which already mount with %s!!\n",
+				bdev->bd_disk->disk_name,
+				bdev->bd_super->s_type->name);
+
 	size -= iocb->ki_pos;
 	if (iov_iter_count(from) > size) {
 		shorted = iov_iter_count(from) - size;