[PATCH v7 42/43] btrfs: disable encryption on RAID5/6

From: Daniel Vacek

Date: Wed May 13 2026 - 05:29:00 EST


From: Josef Bacik <josef@xxxxxxxxxxxxxx>

The RAID5/6 code will re-arrange bios and submit them through a
different mechanism. This is problematic with inline encryption as we
have to get the bio and csum it after it's been encrypted, and the
raid5/6 bio's don't have the btrfs_bio embedded, so we have no way to
get the csums put on disk.

This isn't an unsolvable problem, but would require a bit of reworking.
Since we discourage users from using this code currently simply don't
allow encryption on RAID5/6 setups. If there's sufficient demand in the
future we can add the support for this.

Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Daniel Vacek <neelx@xxxxxxxx>
---

v7 changes:
* Prevent converting to RAID5/6 if encryption is already enabled as
suggested by Chris' AI review.
No changes in v6.
v5: https://lore.kernel.org/linux-btrfs/941f02bb923edadae1aea4ae3e5aa6ba05d1215a.1706116485.git.josef@xxxxxxxxxxxxxx/
---
fs/btrfs/ioctl.c | 4 ++++
fs/btrfs/super.c | 6 ++++++
fs/btrfs/volumes.c | 5 +++++
3 files changed, 15 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2e0b79f41197..873fe08cd19c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5165,6 +5165,10 @@ long btrfs_ioctl(struct file *file, unsigned int
return -EOPNOTSUPP;
if (sb_rdonly(fs_info->sb))
return -EROFS;
+ if (btrfs_fs_incompat(fs_info, RAID56)) {
+ btrfs_warn(fs_info, "can't enable encryption with RAID5/6");
+ return -EINVAL;
+ }
/*
* If we crash before we commit, nothing encrypted could have
* been written so it doesn't matter whether the encrypted
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 7ec07d0bb473..5072ead57d49 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -734,6 +734,12 @@ bool btrfs_check_options(const struct btrfs_fs_info *info,
if (btrfs_check_mountopts_zoned(info, mount_opt))
ret = false;

+ if (btrfs_fs_incompat(info, RAID56) &&
+ btrfs_raw_test_opt(*mount_opt, TEST_DUMMY_ENCRYPTION)) {
+ btrfs_err(info, "cannot use test_dummy_encryption with RAID5/6");
+ ret = false;
+ }
+
if (!test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state)) {
if (btrfs_raw_test_opt(*mount_opt, SPACE_CACHE)) {
btrfs_warn(info,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a88e68f90564..d70735d501c4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6053,6 +6053,11 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,

lockdep_assert_held(&info->chunk_mutex);

+ if (type & BTRFS_BLOCK_GROUP_RAID56_MASK && btrfs_fs_incompat(info, ENCRYPT)) {
+ btrfs_warn(info, "RAID5/6 not yet supported on encrypted filesystem");
+ return ERR_PTR(-EINVAL);
+ }
+
if (!alloc_profile_is_valid(type, 0)) {
DEBUG_WARN("invalid alloc profile for type %llu", type);
return ERR_PTR(-EINVAL);
--
2.53.0