Skip to contentSkip to conversation

common/encrypt, ceph: add _require_not_encrypted test

PATCH In review Jeff Layton 4 participants 4 messages Dec 15, 2021 – Dec 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 common/encrypt, ceph: add _require_not_encrypted test

Some tests on ceph require changing the layout of new files, which is forbidden when the files are encrypted. Add a test that touches a file in $TEST_DIR and then tests it to see if it reports the STATX_ATTR_ENCRYPTED flag, and does a _notrun if it's present.

Also add this requirement to three ceph tests that change the layout.

Cc Luis Henriques <[email protected]>
---
 common/encrypt | 18 ++++++++++++++++++
 tests/ceph/001 |  2 ++
 tests/ceph/002 |  2 ++
 tests/ceph/003 |  2 ++
 4 files changed, 24 insertions(+)

v2: make ceph/001 also call _require_not_encrypted

v3: move test into common/encrypt

common/encrypt +18 -0
index f90c4ef05a3f..156425af40a8 100644
@@ -940,3 +940,21 @@ _filter_nokey_filenames()
 	# of characters that have ever been used in such names.
 	sed "s|${dir}${dir:+/}[A-Za-z0-9+,_-]\+|${dir}${dir:+/}NOKEY_NAME|g"
 }
+
+# Some tests require that encryption not be enabled.
+_require_not_encrypted()
+{
+	local target=$TEST_DIR/require_not_encrypted.$$
+	local ret=0
+
+	#
+	# The top-level directory mounted with test_dummy_encryption is not
+	# itself encrypted. Only new files and directories created under it
+	# are.
+	touch $target
+	local attrs=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')
+	rm -f $target
+
+	# STATX_ATTR_ENCRYPTED == 0x800
+	[ $(( attrs & 0x800 )) -eq 0 ] || _notrun "Filesystem is encrypted"
+}
tests/ceph/001 +2 -0
index c00de308fd95..d6ded026a6dd 100755
@@ -17,11 +17,13 @@ _begin_fstest auto quick copy_range
 . common/filter
 . common/attr
 . common/reflink
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
tests/ceph/002 +2 -0
index 9bc728fd2e18..2232b75e6dfa 100755
@@ -25,11 +25,13 @@ _begin_fstest auto quick copy_range
 # get standard environment
 . common/filter
 . common/attr
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
tests/ceph/003 +2 -0
index faedb48cfeea..aa130ae807f9 100755
@@ -13,11 +13,13 @@ _begin_fstest auto quick copy_range
 . common/filter
 . common/attr
 . common/reflink
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
Signature · 1 line
2.33.1
#1 lore raw
Quoted 36 lines · Jeff Layton

Some tests on ceph require changing the layout of new files, which is forbidden when the files are encrypted. Add a test that touches a file in $TEST_DIR and then tests it to see if it reports the STATX_ATTR_ENCRYPTED flag, and does a _notrun if it's present.

Also add this requirement to three ceph tests that change the layout.

Cc Luis Henriques <[email protected]>
---
 common/encrypt | 18 ++++++++++++++++++
 tests/ceph/001 |  2 ++
 tests/ceph/002 |  2 ++
 tests/ceph/003 |  2 ++
 4 files changed, 24 insertions(+)

v2: make ceph/001 also call _require_not_encrypted

v3: move test into common/encrypt

common/encrypt +8 -0
index f90c4ef05a3f..156425af40a8 100644
@@ -940,3 +940,21 @@ _filter_nokey_filenames()
 	# of characters that have ever been used in such names.
 	sed "s|${dir}${dir:+/}[A-Za-z0-9+,_-]\+|${dir}${dir:+/}NOKEY_NAME|g"
 }
+
+# Some tests require that encryption not be enabled.
+_require_not_encrypted()
+{
+	local target=$TEST_DIR/require_not_encrypted.$$
+	local ret=0
+
+	#

common/encrypt _filter_nokey_filenames() · line 960

Quoted 10 lines
common/encrypt +10 -0
+	# The top-level directory mounted with test_dummy_encryption is not
+	# itself encrypted. Only new files and directories created under it
+	# are.
+	touch $target
+	local attrs=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')
+	rm -f $target
+
+	# STATX_ATTR_ENCRYPTED == 0x800
+	[ $(( attrs & 0x800 )) -eq 0 ] || _notrun "Filesystem is encrypted"
+}

Did you consider instead skipping the test if the mount options contain test_dummy_encryption? That's the way that the encryption tests currently detect that they shouldn't run (since the automatic encryption caused by test_dummy_encryption would interfere with them); see _require_scratch_encryption(). What you've done here will work too, but it might make sense to check for test_dummy_encryption the same way in both places.

- Eric

Reviewed-by on v3 1/1
#2 lore raw
In reply to Jeff Layton
Quoted 16 lines · Jeff Layton

Some tests on ceph require changing the layout of new files, which is forbidden when the files are encrypted. Add a test that touches a file in $TEST_DIR and then tests it to see if it reports the STATX_ATTR_ENCRYPTED flag, and does a _notrun if it's present.

Also add this requirement to three ceph tests that change the layout.

Cc Luis Henriques <[email protected]>
---
 common/encrypt | 18 ++++++++++++++++++
 tests/ceph/001 |  2 ++
 tests/ceph/002 |  2 ++
 tests/ceph/003 |  2 ++
 4 files changed, 24 insertions(+)
Quoted 3 lines

v2: make ceph/001 also call _require_not_encrypted

v3: move test into common/encrypt

Awesome, looks good to me. Feel free to add my

(Although you may send another revision with Eric's suggestion...)

Cheers,
--
Luís

Quoted 83 lines
common/encrypt +18 -0
index f90c4ef05a3f..156425af40a8 100644
@@ -940,3 +940,21 @@ _filter_nokey_filenames()
 	# of characters that have ever been used in such names.
 	sed "s|${dir}${dir:+/}[A-Za-z0-9+,_-]\+|${dir}${dir:+/}NOKEY_NAME|g"
 }
+
+# Some tests require that encryption not be enabled.
+_require_not_encrypted()
+{
+	local target=$TEST_DIR/require_not_encrypted.$$
+	local ret=0
+
+	#
+	# The top-level directory mounted with test_dummy_encryption is not
+	# itself encrypted. Only new files and directories created under it
+	# are.
+	touch $target
+	local attrs=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')
+	rm -f $target
+
+	# STATX_ATTR_ENCRYPTED == 0x800
+	[ $(( attrs & 0x800 )) -eq 0 ] || _notrun "Filesystem is encrypted"
+}
tests/ceph/001 +2 -0
index c00de308fd95..d6ded026a6dd 100755
@@ -17,11 +17,13 @@ _begin_fstest auto quick copy_range
 . common/filter
 . common/attr
 . common/reflink
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
tests/ceph/002 +2 -0
index 9bc728fd2e18..2232b75e6dfa 100755
@@ -25,11 +25,13 @@ _begin_fstest auto quick copy_range
 # get standard environment
 . common/filter
 . common/attr
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
tests/ceph/003 +2 -0
index faedb48cfeea..aa130ae807f9 100755
@@ -13,11 +13,13 @@ _begin_fstest auto quick copy_range
 . common/filter
 . common/attr
 . common/reflink
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
Signature · 1 line
2.33.1
#3 lore raw
In reply to Jeff Layton
Quoted 25 lines · Jeff Layton

Some tests on ceph require changing the layout of new files, which is forbidden when the files are encrypted. Add a test that touches a file in $TEST_DIR and then tests it to see if it reports the STATX_ATTR_ENCRYPTED flag, and does a _notrun if it's present.

Also add this requirement to three ceph tests that change the layout.

Cc Luis Henriques <[email protected]>
---
 common/encrypt | 18 ++++++++++++++++++
 tests/ceph/001 |  2 ++
 tests/ceph/002 |  2 ++
 tests/ceph/003 |  2 ++
 4 files changed, 24 insertions(+)

v2: make ceph/001 also call _require_not_encrypted

v3: move test into common/encrypt

common/encrypt +0 -0
index f90c4ef05a3f..156425af40a8 100644

common/encrypt _filter_nokey_filenames() · line 945

Quoted 6 lines
common/encrypt +3 -0
@@ -940,3 +940,21 @@ _filter_nokey_filenames()
 	# of characters that have ever been used in such names.
 	sed "s|${dir}${dir:+/}[A-Za-z0-9+,_-]\+|${dir}${dir:+/}NOKEY_NAME|g"
 }
+
+# Some tests require that encryption not be enabled.
+_require_not_encrypted()

We have some other helpers that require something not enabled or present, and they're all in the format as:

_require_no_compress()
_require_no_realtime()
_require_no_xfs_debug()

So how about name it as _require_no_encryption() to be consistent with other functions?

common/encrypt _filter_nokey_filenames() · line 955

Quoted 10 lines
common/encrypt +10 -0
+{
+	local target=$TEST_DIR/require_not_encrypted.$$
+	local ret=0
+
+	#
+	# The top-level directory mounted with test_dummy_encryption is not
+	# itself encrypted. Only new files and directories created under it
+	# are.
+	touch $target
+	local attrs=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')

I think we may need to check if statx is supported as well

_require_xfs_io_command "statx" "-r"

Thanks,
Eryu

Quoted 61 lines
common/encrypt +5 -0
+	rm -f $target
+
+	# STATX_ATTR_ENCRYPTED == 0x800
+	[ $(( attrs & 0x800 )) -eq 0 ] || _notrun "Filesystem is encrypted"
+}
tests/ceph/001 +2 -0
index c00de308fd95..d6ded026a6dd 100755
@@ -17,11 +17,13 @@ _begin_fstest auto quick copy_range
 . common/filter
 . common/attr
 . common/reflink
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
tests/ceph/002 +2 -0
index 9bc728fd2e18..2232b75e6dfa 100755
@@ -25,11 +25,13 @@ _begin_fstest auto quick copy_range
 # get standard environment
 . common/filter
 . common/attr
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
tests/ceph/003 +2 -0
index faedb48cfeea..aa130ae807f9 100755
@@ -13,11 +13,13 @@ _begin_fstest auto quick copy_range
 . common/filter
 . common/attr
 . common/reflink
+. common/encrypt
 
 # real QA test starts here
 _supported_fs ceph
 
 _require_xfs_io_command "copy_range"
+_require_not_encrypted
 _require_attrs
 _require_test
 
Signature · 1 line
2.33.1