diff mbox series

[3/3] ext4: notify when device not supprt inlinecrypt

Message ID 20220418063312.63181-3-changfengnan@vivo.com (mailing list archive)
State New, archived
Headers show
Series [1/3] blk-crypto: introduce blk_crypto_supported | expand

Commit Message

常凤楠 April 18, 2022, 6:33 a.m. UTC
Notify when mount filesystem with -o inlinecrypt option, but the device
not support inlinecrypt.

Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
---
 fs/ext4/super.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 81749eaddf4c..f91454d3a877 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -48,6 +48,7 @@ 
 #include <linux/fsnotify.h>
 #include <linux/fs_context.h>
 #include <linux/fs_parser.h>
+#include <linux/blk-crypto.h>
 
 #include "ext4.h"
 #include "ext4_extents.h"	/* Needed for trace points definition */
@@ -5466,6 +5467,17 @@  static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 				 "the device does not support discard");
 	}
 
+#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
+	if (sb->s_flags & SB_INLINECRYPT) {
+		struct request_queue *q = bdev_get_queue(sb->s_bdev);
+
+		if (!blk_crypto_supported(q)) {
+			ext4_msg(sb, KERN_WARNING,
+			 "mounting with \"inlinecrypt\" option, but the device does not support inlinecrypt");
+			sb->s_flags &= ~SB_INLINECRYPT;
+		}
+	}
+#endif
+
 	if (es->s_error_count)
 		mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */