Notify when mount filesystem with -o inlinecrypt option, but the device
not support inlinecrypt.

Signed-off-by: Fengnan Chang <[email protected]>
---
 fs/f2fs/f2fs.h  | 18 ++++++++++++++++++
 fs/f2fs/super.c |  7 +++++++
 2 files changed, 25 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 38cbed0f544e..dc27a708c283 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -27,6 +27,7 @@
 
 #include <linux/fscrypt.h>
 #include <linux/fsverity.h>
+#include <linux/blk-crypto.h>
 
 struct pagevec;
 
@@ -4395,6 +4396,23 @@ static inline bool f2fs_realtime_discard_enable(struct 
f2fs_sb_info *sbi)
                                        f2fs_hw_should_discard(sbi);
 }
 
+#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
+static inline bool f2fs_hw_support_crypto(struct f2fs_sb_info *sbi)
+{
+       int i;
+
+       if (!f2fs_is_multi_device(sbi))
+               if (!blk_crypto_supported(bdev_get_queue(sbi->sb->s_bdev)))
+                       return false;
+
+       for (i = 0; i < sbi->s_ndevs; i++)
+               if (!blk_crypto_supported(bdev_get_queue(FDEV(i).bdev)))
+                       return false;
+
+       return true;
+}
+#endif
+
 static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi)
 {
        int i;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 4368f90571bd..624d8791b82d 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1275,6 +1275,13 @@ static int parse_options(struct super_block *sb, char 
*options, bool is_remount)
        }
 #endif
 
+#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
+       if ((sb->s_flags & SB_INLINECRYPT) && !f2fs_hw_support_crypto(sbi)) {
+               f2fs_info(sbi, "mounting with \"inlinecrypt\" option, but the 
device does not support inlinecrypt");
+               sb->s_flags &= ~SB_INLINECRYPT;
+       }
+#endif
+
        if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
                f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                         F2FS_IO_SIZE_KB(sbi));
-- 
2.32.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to