From 33322f3a24882dc3ab8ffbb4aab2a0ed28cfe15c Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Thu, 3 Dec 2020 15:43:29 +0100 Subject: [PATCH] LU-14149 llite: fiemap set flags for encrypted files FIEMAP ioctl needs to set FIEMAP_EXTENT_DATA_ENCRYPTED|FIEMAP_EXTENT_ENCODED flags for all extents of files encrypted by fscrypt. Also add sanity-sec test_56 to exercise the flags, with just a plain file layout for now. Signed-off-by: Sebastien Buisson Change-Id: I26f788b5c4b37e96de57334f48847b40886e14c2 Reviewed-on: https://review.whamcloud.com/40852 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Lai Siyao --- lustre/llite/file.c | 9 +++++++++ lustre/tests/sanity-sec.sh | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 5e3debe..2da3896 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -5113,6 +5113,15 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, rc = ll_do_fiemap(inode, fiemap, num_bytes); + if (IS_ENCRYPTED(inode)) { + int i; + + for (i = 0; i < fiemap->fm_mapped_extents; i++) + fiemap->fm_extents[i].fe_flags |= + FIEMAP_EXTENT_DATA_ENCRYPTED | + FIEMAP_EXTENT_ENCODED; + } + fieinfo->fi_flags = fiemap->fm_flags; fieinfo->fi_extents_mapped = fiemap->fm_mapped_extents; if (extent_count > 0 && diff --git a/lustre/tests/sanity-sec.sh b/lustre/tests/sanity-sec.sh index 449b54e..8b0900c 100755 --- a/lustre/tests/sanity-sec.sh +++ b/lustre/tests/sanity-sec.sh @@ -4143,6 +4143,30 @@ test_55() { } run_test 55 "access with seteuid" +test_56() { + local testfile=$DIR/$tdir/$tfile + + $LCTL get_param mdc.*.import | grep -q client_encryption || + skip "client encryption not supported" + + mount.lustre --help |& grep -q "test_dummy_encryption:" || + skip "need dummy encryption support" + + [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" + + stack_trap cleanup_for_enc_tests EXIT + setup_for_enc_tests + + $LFS setstripe -c2 -i0 -S 1M $testfile + dd if=/dev/urandom of=$testfile bs=1M count=3 conv=fsync + filefrag -v $testfile || error "filefrag $testfile failed" + (( $(filefrag -v $testfile | grep -c encrypted) >= 2 )) || + error "filefrag $testfile does not show encrypted flag" + (( $(filefrag -v $testfile | grep -c encoded) >= 2 )) || + error "filefrag $testfile does not show encoded flag" +} +run_test 56 "FIEMAP on encrypted file" + log "cleanup: ======================================================" sec_unsetup() { -- 1.8.3.1