Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Daniel Vacek <neelx@suse.com>
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-xfs@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net, zlang@redhat.com,
	hch@infradead.org, djwong@kernel.org,
	David Sterba <dsterba@suse.com>, Daniel Vacek <neelx@suse.com>,
	linux-fscrypt@vger.kernel.org,
	Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Subject: [PATCH 06/12] btrfs: add simple test of reflink of encrypted data
Date: Fri, 24 Jul 2026 15:33:22 +0200	[thread overview]
Message-ID: <20260724133328.1837318-7-neelx@suse.com> (raw)
In-Reply-To: <20260724133328.1837318-1-neelx@suse.com>

From: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>

Make sure that we succeed at reflinking encrypted data.

Test deliberately numbered with a high number so it won't conflict with
tests between now and merge.

v1:
    An array overflow bug in btrfs_check_encrypted_read_bio() was hidden
    during fscrypt v6 32/43 patch development until the file size was
    extended to more than 144k (16k + 64k + >64k a.k.a. BTRFS_MAX_BLOCKSIZE
    - it was 33k before).
    We simply needed more pages in the game to run out of the array.

    Even-though the bug was fixed in v7, it may be useful to keep this
    test checking, just to be sure nothing similar happens in the future.

Signed-off-by: Daniel Vacek <neelx@suse.com>
---
 tests/btrfs/613     | 54 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/613.out | 13 +++++++++++
 2 files changed, 67 insertions(+)
 create mode 100755 tests/btrfs/613
 create mode 100644 tests/btrfs/613.out

diff --git a/tests/btrfs/613 b/tests/btrfs/613
new file mode 100755
index 00000000..fddb9243
--- /dev/null
+++ b/tests/btrfs/613
@@ -0,0 +1,54 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 Meta Platforms, Inc.  All Rights Reserved.
+#
+# FS QA Test 613
+#
+# Check if reflinking one encrypted file on btrfs succeeds.
+#
+. ./common/preamble
+_begin_fstest auto encrypt
+
+# Import common functions.
+. ./common/encrypt
+. ./common/filter
+. ./common/reflink
+
+_require_test
+_require_scratch
+_require_cp_reflink
+_require_scratch_encryption -v 2
+_require_command "$KEYCTL_PROG" keyctl
+
+_scratch_mkfs_encrypted &>> $seqres.full
+_scratch_mount
+
+dir=$SCRATCH_MNT/dir
+mkdir $dir
+_set_encpolicy $dir $TEST_KEY_IDENTIFIER
+_add_enckey $SCRATCH_MNT "$TEST_RAW_KEY"
+echo "Creating and reflinking a file"
+$XFS_IO_PROG -t -f -c "pwrite 0 145k" $dir/test > /dev/null
+cp --reflink=always $dir/test $dir/test2
+
+echo "Can't reflink encrypted and unencrypted"
+cp --reflink=always $dir/test $SCRATCH_MNT/fail |& _filter_scratch
+
+echo "Diffing the file and its copy"
+diff $dir/test $dir/test2
+
+echo "Verifying the files are reflinked"
+_verify_reflink $dir/test $dir/test2
+
+echo "Diffing the files after remount"
+_scratch_cycle_mount
+_add_enckey $SCRATCH_MNT "$TEST_RAW_KEY"
+diff $dir/test $dir/test2
+
+echo "Diffing the files after key remove"
+_rm_enckey $SCRATCH_MNT $TEST_KEY_IDENTIFIER
+diff $dir/test $dir/test2 |& _filter_scratch
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/613.out b/tests/btrfs/613.out
new file mode 100644
index 00000000..4895d6dd
--- /dev/null
+++ b/tests/btrfs/613.out
@@ -0,0 +1,13 @@
+QA output created by 613
+Added encryption key with identifier 69b2f6edeee720cce0577937eb8a6751
+Creating and reflinking a file
+Can't reflink encrypted and unencrypted
+cp: failed to clone 'SCRATCH_MNT/fail' from 'SCRATCH_MNT/dir/test': Invalid argument
+Diffing the file and its copy
+Verifying the files are reflinked
+Diffing the files after remount
+Added encryption key with identifier 69b2f6edeee720cce0577937eb8a6751
+Diffing the files after key remove
+Removed encryption key with identifier 69b2f6edeee720cce0577937eb8a6751
+diff: SCRATCH_MNT/dir/test: No such file or directory
+diff: SCRATCH_MNT/dir/test2: No such file or directory
-- 
2.53.0


  parent reply	other threads:[~2026-07-24 13:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 13:33 [PATCH 00/12] fstests: introduce fscrypt support for btrfs Daniel Vacek
2026-07-24 13:33 ` [PATCH 01/12] common/encrypt: separate data and inode nonces Daniel Vacek
2026-07-24 13:33 ` [PATCH 02/12] common/encrypt: add btrfs to get_encryption_*nonce Daniel Vacek
2026-07-24 13:33 ` [PATCH 03/12] common/encrypt: add btrfs to get_ciphertext_filename Daniel Vacek
2026-07-24 13:33 ` [PATCH 04/12] common/encrypt: enable making a encrypted btrfs filesystem Daniel Vacek
2026-07-24 13:33 ` [PATCH 05/12] common/verity: explicitly don't allow btrfs encryption Daniel Vacek
2026-07-24 13:33 ` Daniel Vacek [this message]
2026-07-24 13:33 ` [PATCH 07/12] btrfs: test snapshotting encrypted subvol Daniel Vacek
2026-07-24 13:33 ` [PATCH 08/12] fstests: properly test for v1 encryption policies in encrypt tests Daniel Vacek
2026-07-24 13:33 ` [PATCH 09/12] fstests: split generic/580 into two tests Daniel Vacek
2026-07-24 13:33 ` [PATCH 10/12] fstests: split generic/581 " Daniel Vacek
2026-07-24 13:33 ` [PATCH 11/12] fstests: split generic/613 " Daniel Vacek
2026-07-24 13:33 ` [PATCH 12/12] fscrypt-crypt-util: add support for per extent KDF Daniel Vacek
2026-07-28  3:19 ` [PATCH 00/12] fstests: introduce fscrypt support for btrfs Christoph Hellwig
2026-07-28  5:44   ` Daniel Vacek
2026-07-28  5:48     ` Eric Biggers
2026-07-28  6:04       ` Christoph Hellwig
2026-07-28  6:07         ` Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724133328.1837318-7-neelx@suse.com \
    --to=neelx@suse.com \
    --cc=djwong@kernel.org \
    --cc=dsterba@suse.com \
    --cc=fstests@vger.kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sweettea-kernel@dorminy.me \
    --cc=zlang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox