From: Artem Blagodarenko Test ext4 LUFID functionality in the complex combination of encryption, casefold (case-insensitive), and dirdata features. Verification uses 'debugfs ls -lD' to check for 'fid: or hash:' markers. Tests also verify that case-insensitive lookups work correctly and that encrypted file content is preserved after setting LUFID. This test validates that LUFID works correctly when encryption and casefold features are enabled, ensuring feature interactions don't break the LUFID functionality. Signed-off-by: Artem Blagodarenko --- tests/ext4/067 | 137 +++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/067.out | 4 ++ 2 files changed, 141 insertions(+) diff --git a/tests/ext4/067 b/tests/ext4/067 new file mode 100755 index 00000000..acb49c40 --- /dev/null +++ b/tests/ext4/067 @@ -0,0 +1,137 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 The Lustre Collective. All Rights Reserved. +# Author: Artem Blagodarenko +# +# FS QA Test ext4/067 +# +# Test ext4 LUFID with encryption and casefold. +# EXT4_IOC_SET_LUFID is an ioctl that allows LUFID data to be set on a directory entry. +# directory name hash is stored by EXT4 when casefold and encryption features are enabled. + +. ./common/preamble +_begin_fstest auto quick encrypt casefold + +# Import common functions +. ./common/filter +. ./common/encrypt +. ./common/casefold +. ./common/attr +. ./common/ext4 + +_exclude_fs ext2 +_exclude_fs ext3 + +_require_scratch_nocheck +_require_scratch_encryption +_require_scratch_casefold +_require_command "$SET_LUFID_PROG" + +# Check if dirdata feature is supported (required for LUFID IOCTL) +_require_scratch_dirdata() +{ + if test ! -f /sys/fs/ext4/features/dirdata ; then + _notrun "dirdata feature not supported by kernel (required for LUFID)" + fi + + # Verify that mkfs supports dirdata + if ! $MKFS_EXT4_PROG -O dirdata -n $SCRATCH_DEV &>>$seqres.full ; then + _notrun "mkfs.ext4 does not support dirdata feature" + fi + + # Verify kernel can mount filesystem with encrypt+casefold+dirdata + if ! _scratch_mkfs -O encrypt,casefold,dirdata &>>$seqres.full ; then + _notrun "failed to create filesystem with encrypt+casefold+dirdata" + fi + if ! _try_scratch_mount &>>$seqres.full ; then + _notrun "kernel cannot mount filesystem with encrypt+casefold+dirdata" + fi + _scratch_unmount +} + +_require_scratch_dirdata + +# Helper to add a v2 encryption key and set policy on a directory +_setup_encrypted_dir() +{ + local dir=$1 + local raw_key=$(_generate_raw_encryption_key) + local keyspec=$(_add_enckey $SCRATCH_MNT "$raw_key" | awk '{print $NF}') + _set_encpolicy $dir $keyspec + _casefold_set_attr $dir + echo $keyspec +} + +# Create a filesystem with encryption, casefold, and dirdata features +_scratch_mkfs -O encrypt,casefold,dirdata &>>$seqres.full +_scratch_mount + +# Test: Create file in encrypted+casefolded directory and set three 16-byte LUFIDs +echo "Test: Set three 16-byte LUFIDs on file in encrypted+casefolded directory" +mkdir $SCRATCH_MNT/encrypted_dir +_setup_encrypted_dir $SCRATCH_MNT/encrypted_dir > /dev/null + +echo "encrypted content" > $SCRATCH_MNT/encrypted_dir/testfile.txt + +lufid_payload=$'\xde\xad\xbe\xef\x01\x02\x03\x04\x11\x12\x13\x14\x21\x22\x23\x24\xca\xfe\xba\xbe\x05\x06\x07\x08\x31\x32\x33\x34\x41\x42\x43\x44\xfe\xed\xfa\xce\x09\x0a\x0b\x0c\x51\x52\x53\x54\x61\x62\x63\x64' +expected_fid='[0xdeadbeef01020304:0x11121314:0x21222324],[0xcafebabe05060708:0x31323334:0x41424344],[0xfeedface090a0b0c:0x51525354:0x61626364]' + +# Set three LUFIDs on the file at the same time (48 bytes total: three 16-byte FIDs) +# First FID: [part1 (8 bytes):part2 (4 bytes):part3 (4 bytes)] +# Second FID: [part1 (8 bytes):part2 (4 bytes):part3 (4 bytes)] +# Third FID: [part1 (8 bytes):part2 (4 bytes):part3 (4 bytes)] +set_lufid $SCRATCH_MNT/encrypted_dir testfile.txt "$lufid_payload" >>$seqres.full 2>&1 +if [ $? -ne 0 ]; then + echo "FAIL: Could not set three LUFIDs on encrypted+casefolded file" + _scratch_unmount + _check_scratch_fs + status=1 + exit +fi + +# Verify file is still accessible +if [ ! -f $SCRATCH_MNT/encrypted_dir/testfile.txt ]; then + echo "FAIL: Encrypted file not accessible after setting LUFID" + _scratch_unmount + _check_scratch_fs + status=1 + exit +fi + +# Verify file content is preserved +enc_content=$(cat $SCRATCH_MNT/encrypted_dir/testfile.txt 2>/dev/null) +if [ "$enc_content" != "encrypted content" ]; then + echo "FAIL: Encrypted file content not preserved after setting LUFID" + _scratch_unmount + _check_scratch_fs + status=1 + exit +fi + +# Test case-insensitive lookup still works with LUFID +if [ ! -f "$SCRATCH_MNT/encrypted_dir/TESTFILE.TXT" ]; then + echo "FAIL: Case-insensitive lookup doesn't work with LUFID" + _scratch_unmount + _check_scratch_fs + status=1 + exit +fi + +echo "Successfully set and verified three 16-byte LUFIDs on encrypted+casefolded file" + +# Dump directory structure to verify dirdata +if ! _dump_dir_structure $SCRATCH_MNT/encrypted_dir testfile.txt "$expected_fid"; then + echo "FAIL: Stored LUFID does not match expected value" + _scratch_unmount + _check_scratch_fs + status=1 + exit +fi + +# Cleanup and verify filesystem +_scratch_unmount +_check_scratch_fs + +# success, all done +status=0 +exit diff --git a/tests/ext4/067.out b/tests/ext4/067.out new file mode 100644 index 00000000..1c9a8126 --- /dev/null +++ b/tests/ext4/067.out @@ -0,0 +1,4 @@ +QA output created by 067 +Test: Set three 16-byte LUFIDs on file in encrypted+casefolded directory +Successfully set and verified three 16-byte LUFIDs on encrypted+casefolded file + Directory structure of encrypted_dir: OK (dirdata verified) -- 2.43.7