Whamcloud - gitweb
LU-14149 llite: fiemap set flags for encrypted files 52/40852/5
authorSebastien Buisson <sbuisson@ddn.com>
Thu, 3 Dec 2020 14:43:29 +0000 (15:43 +0100)
committerOleg Drokin <green@whamcloud.com>
Thu, 17 Dec 2020 17:00:31 +0000 (17:00 +0000)
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 <sbuisson@ddn.com>
Change-Id: I26f788b5c4b37e96de57334f48847b40886e14c2
Reviewed-on: https://review.whamcloud.com/40852
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
lustre/llite/file.c
lustre/tests/sanity-sec.sh

index 5e3debe..2da3896 100644 (file)
@@ -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 &&
index 449b54e..8b0900c 100755 (executable)
@@ -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() {