Skip to contentSkip to conversation

Improve I/O tests coverage of LUKS

PATCH Superseded Daniel P. Berrange 2 participants 7 messages May 2, 2017 – May 9, 2017

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Improve I/O tests coverage of LUKS

The main goal of this series is to get the I/O tests passing 100% with LUKS when run with './check -luks'. It also adds a few more combinations to the LUKS/dmcrypt interoperability test.

To make LUKS testing not quite as slow, we drop the PBKDF iteration count down to a very small value. This doesn't remove all overhead, as formatting the volume will always measure PBKDF timing over a 1 second interval.

Changed in v4:

- Fix misc mistakes in syntax conversion (Max)
- Drop changes to 120 & mark it unsupported (Max)
- Use _unsupported_fmt (Max)

Changed in v3:

- Fix some typos in commit message(s) (Eric)

Changed in v2:

- Split off patch that change check.time recording since it was not a direct dependancy
- Skip new 159 & 170 tests which don't work due to qemu-img dd limitations

Daniel P. Berrange (5):
iotests: skip 159 & 170 with luks format
iotests: fix remainining tests to work with LUKS
iotests: reduce PBKDF iterations when testing LUKS
iotests: add more LUKS hash combination tests
iotests: chown LUKS device before qemu-io launches

 tests/qemu-iotests/033           |   12 +-
 tests/qemu-iotests/120           |    1 +
 tests/qemu-iotests/140           |   15 +-
 tests/qemu-iotests/145           |   18 +-
 tests/qemu-iotests/149           |   26 +-
 tests/qemu-iotests/149.out       | 1002 ++++++++++++++++++++++++++++----------
 tests/qemu-iotests/157           |   17 +-
 tests/qemu-iotests/157.out       |   16 +-
 tests/qemu-iotests/159           |    1 +
 tests/qemu-iotests/170           |    1 +
 tests/qemu-iotests/174           |    2 +-
 tests/qemu-iotests/common.filter |    3 +-
 tests/qemu-iotests/common.rc     |    3 +
 13 files changed, 825 insertions(+), 292 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v4 1/5 iotests: skip 159 & 170 with luks format

While the qemu-img dd command does accept --image-opts this is not sufficient to make it work with the LUKS image yet. This is because bdrv_create() still always requires the non-image-opts syntax.

Thus we must skip 159/170 with luks for now

---
 tests/qemu-iotests/159 | 1 +
 tests/qemu-iotests/170 | 1 +
 2 files changed, 2 insertions(+)
tests/qemu-iotests/159 +1 -0
index 825f05f..9b0e1ec 100755
@@ -40,6 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 _supported_fmt generic
 _supported_proto file
 _supported_os Linux
+_unsupported_fmt luks
 
 TEST_SIZES="5 512 1024 1999 1K 64K 1M"
 
tests/qemu-iotests/170 +1 -0
index 5b335db..b79359f 100755
@@ -40,6 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 _supported_fmt generic
 _supported_proto file
 _supported_os Linux
+_unsupported_fmt luks
 
 echo
 echo "== Creating image =="
Signature · 1 line
2.9.3
#2 lore raw

PATCH v4 2/5 iotests: fix remainining tests to work with LUKS

In reply to Daniel P. Berrange

The tests 033, 140, 145 and 157 were all broken when run with LUKS, since they did not correctly use the required image opts args syntax to specify the decryption secret. Further, the 120 test simply does not make sense to run with luks, as the scenario exercised is not relevant.

---
 tests/qemu-iotests/033     | 12 ++++++++++--
 tests/qemu-iotests/120     |  1 +
 tests/qemu-iotests/140     | 15 ++++++++++++++-
 tests/qemu-iotests/145     | 18 +++++++++++++++++-
 tests/qemu-iotests/157     | 17 ++++++++++++++---
 tests/qemu-iotests/157.out | 16 ++++++++--------
 tests/qemu-iotests/174     |  2 +-
 7 files changed, 65 insertions(+), 16 deletions(-)
tests/qemu-iotests/033 +10 -2
index 16edcf2..2cdfd13 100755
@@ -50,10 +50,18 @@ do_test()
 	local align=$1
 	local iocmd=$2
 	local img=$3
+	if [ "$IMGOPTSSYNTAX" = "true" ]
+	then
+	    IO_OPEN_ARG="$img"
+	    IO_EXTRA_ARGS="--image-opts"
+	else
+	    IO_OPEN_ARG="-o driver=$IMGFMT,file.align=$align blkdebug::$img"
+	    IO_EXTRA_ARGS=""
+	fi
 	{
-		echo "open -o driver=$IMGFMT,file.align=$align blkdebug::$img"
+		echo "open $IO_OPEN_ARG"
 		echo $iocmd
-	} | $QEMU_IO
+	} | $QEMU_IO $IO_EXTRA_ARGS
 }
 
 for write_zero_cmd in "write -z" "aio_write -z"; do
tests/qemu-iotests/120 +1 -0
index 4f88a67..f40b97d 100755
@@ -41,6 +41,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 _supported_fmt generic
 _supported_proto file
 _supported_os Linux
+_unsupported_fmt luks
 
 _make_test_img 64M
 
tests/qemu-iotests/140 +14 -1
index 8c80a5a..153982d 100755
@@ -52,8 +52,21 @@ _make_test_img 64k
 
 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
 
+if test "$IMGOPTSSYNTAX" = "true"
+then
+    SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,$TEST_IMG
+    SYSEMU_EXTRA_ARGS=""
+    if [ -n "$IMGKEYSECRET" ]; then
+        SECRET_ARG="secret,id=keysec0,data=$IMGKEYSECRET"
+        SYSEMU_EXTRA_ARGS="-object $SECRET_ARG"
+    fi
+else
+    SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,file="$TEST_IMG",driver=$IMGFMT
+    SYSEMU_EXTRA_ARGS=""
+fi
+
 keep_stderr=y \
-_launch_qemu -drive if=none,media=cdrom,id=drv,file="$TEST_IMG",format=$IMGFMT \
+_launch_qemu $SYSEMU_EXTRA_ARGS -drive $SYSEMU_DRIVE_ARG \
     2> >(_filter_nbd)
 
 _send_qemu_cmd $QEMU_HANDLE \
tests/qemu-iotests/145 +17 -1
index 1eca0e8..8dfce34 100755
@@ -43,7 +43,23 @@ _supported_proto generic
 _supported_os Linux
 
 _make_test_img 1M
-echo quit | $QEMU -nographic -hda "$TEST_IMG" -incoming 'exec:true' -snapshot -serial none -monitor stdio | _filter_qemu
+
+if test "$IMGOPTSSYNTAX" = "true"
+then
+    SYSEMU_DRIVE_ARG=if=none,$TEST_IMG
+    SYSEMU_EXTRA_ARGS=""
+    if [ -n "$IMGKEYSECRET" ]; then
+	SECRET_ARG="secret,id=keysec0,data=$IMGKEYSECRET"
+	SYSEMU_EXTRA_ARGS="-object $SECRET_ARG"
+    fi
+else
+    SYSEMU_DRIVE_ARG=if=none,file="$TEST_IMG",driver=$IMGFMT
+    SYSEMU_EXTRA_ARGS=""
+fi
+
+echo quit | $QEMU -nographic $SYSEMU_EXTRA_ARGS  -drive $SYSEMU_DRIVE_ARG \
+                  -incoming 'exec:true' -snapshot -serial none -monitor stdio \
+          | _filter_qemu
 
 # success, all done
 echo "*** done"
tests/qemu-iotests/157 +14 -3
index 8d939cb..f5d22fa 100755
@@ -43,7 +43,6 @@ _supported_os Linux
 
 function do_run_qemu()
 {
-    echo Testing: "$@"
     (
         if ! test -t 0; then
             while read cmd; do
@@ -63,7 +62,18 @@ function run_qemu()
 
 
 size=128M
-drive="if=none,file=$TEST_IMG,driver=$IMGFMT"
+if test "$IMGOPTSSYNTAX" = "true"
+then
+    SYSEMU_DRIVE_ARG=if=none,$TEST_IMG
+    SYSEMU_EXTRA_ARGS=""
+    if [ -n "$IMGKEYSECRET" ]; then
+	SECRET_ARG="secret,id=keysec0,data=$IMGKEYSECRET"
+	SYSEMU_EXTRA_ARGS="-object $SECRET_ARG"
+    fi
+else
+    SYSEMU_DRIVE_ARG=if=none,file="$TEST_IMG",driver=$IMGFMT
+    SYSEMU_EXTRA_ARGS=""
+fi
 
 _make_test_img $size
 
@@ -76,8 +86,9 @@ echo
 
 for cache in "writeback" "writethrough"; do
     for wce in "" ",write-cache=auto" ",write-cache=on" ",write-cache=off"; do
+        echo "Testing: cache='$cache' wce='$wce'"
         echo "info block" \
-            | run_qemu -drive "$drive,cache=$cache" \
+            | run_qemu $SYSEMU_EXTRA_ARGS -drive "$SYSEMU_DRIVE_ARG,cache=$cache" \
                        -device "virtio-blk,drive=none0$wce" \
             | grep -e "Testing" -e "Cache mode"
     done
tests/qemu-iotests/157.out +8 -8
index 77a9c03..fdc807f 100644
@@ -3,20 +3,20 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
 
 === Setting WCE with qdev and with manually created BB ===
 
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writeback -device virtio-blk,drive=none0
+Testing: cache='writeback' wce=''
     Cache mode:       writeback
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writeback -device virtio-blk,drive=none0,write-cache=auto
+Testing: cache='writeback' wce=',write-cache=auto'
     Cache mode:       writeback
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writeback -device virtio-blk,drive=none0,write-cache=on
+Testing: cache='writeback' wce=',write-cache=on'
     Cache mode:       writeback
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writeback -device virtio-blk,drive=none0,write-cache=off
+Testing: cache='writeback' wce=',write-cache=off'
     Cache mode:       writethrough
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writethrough -device virtio-blk,drive=none0
+Testing: cache='writethrough' wce=''
     Cache mode:       writethrough
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writethrough -device virtio-blk,drive=none0,write-cache=auto
+Testing: cache='writethrough' wce=',write-cache=auto'
     Cache mode:       writethrough
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writethrough -device virtio-blk,drive=none0,write-cache=on
+Testing: cache='writethrough' wce=',write-cache=on'
     Cache mode:       writeback
-Testing: -drive if=none,file=TEST_DIR/t.IMGFMT,driver=IMGFMT,cache=writethrough -device virtio-blk,drive=none0,write-cache=off
+Testing: cache='writethrough' wce=',write-cache=off'
     Cache mode:       writethrough
 *** done
tests/qemu-iotests/174 +1 -1
index c1c20a1..552879d 100755
@@ -41,7 +41,7 @@ _unsupported_fmt raw
 
 
 size=256K
-IMGFMT=raw IMGOPTS= _make_test_img $size | _filter_imgfmt
+IMGFMT=raw IMGKEYSECRET= IMGOPTS= _make_test_img $size | _filter_imgfmt
 
 echo
 echo "== reading wrong format should fail =="
Signature · 1 line
2.9.3
#3 lore raw

PATCH v4 3/5 iotests: reduce PBKDF iterations when testing LUKS

In reply to Daniel P. Berrange

By default the PBKDF algorithm used with LUKS is tuned based on the number of iterations to produce 1 second of running time. This makes running the I/O test with the LUKS format orders of magnitude slower than with qcow2/raw formats.

When creating LUKS images, set the iteration time to a 10ms to reduce the time overhead for LUKS, since security does not matter in I/O tests.

Previously a full 'check -luks' would take

  $ time ./check -luks
  Passed all 22 tests
  real  23m9.988s
  user  21m46.223s
  sys   0m22.841s

Now it takes

  $ time ./check -luks
  Passed all 22 tests
  real  4m39.235s
  user  3m29.590s
  sys   0m24.234s

Still slow compared to qcow2/raw, but much improved none the less.

---
 tests/qemu-iotests/149           |   3 +
 tests/qemu-iotests/149.out       | 118 +++++++++++++++++++--------------------
 tests/qemu-iotests/common.filter |   3 +-
 tests/qemu-iotests/common.rc     |   3 +
 4 files changed, 67 insertions(+), 60 deletions(-)
tests/qemu-iotests/149 +3 -0
index 8407251..f62e618 100755
@@ -136,6 +136,7 @@ def cryptsetup_add_password(config, slot):
         args = ["luksAddKey", config.image_path(),
                 "--key-slot", slot,
                 "--key-file", "-",
+                "--iter-time", "10",
                 pwfile]
 
         cryptsetup(args, password)
@@ -164,6 +165,7 @@ def cryptsetup_format(config):
         args.extend(["--hash", config.hash])
     args.extend(["--key-slot", slot])
     args.extend(["--key-file", "-"])
+    args.extend(["--iter-time", "10"])
     args.append(config.image_path())
 
     cryptsetup(args, password)
@@ -230,6 +232,7 @@ def qemu_img_create(config, size_mb):
 
     opts = [
         "key-secret=sec0",
+        "iter-time=10",
         "cipher-alg=%s-%d" % (config.cipher, config.keylen),
         "cipher-mode=%s" % config.mode,
         "ivgen-alg=%s" % config.ivgen,
tests/qemu-iotests/149.out +59 -59

335 lines not on this page · raw message

tests/qemu-iotests/common.filter +2 -1
index c9a2d5c..2983553 100644
@@ -113,7 +113,8 @@ _filter_img_create()
         -e "s# block_state_zero=\\(on\\|off\\)##g" \
         -e "s# log_size=[0-9]\\+##g" \
         -e "s# refcount_bits=[0-9]\\+##g" \
-        -e "s# key-secret=[a-zA-Z0-9]\\+##g"
+        -e "s# key-secret=[a-zA-Z0-9]\\+##g" \
+        -e "s# iter-time=[0-9]\\+##g"
 }
 
 _filter_img_info()
tests/qemu-iotests/common.rc +3 -0
index 62529ee..069a8b3 100644
@@ -107,6 +107,9 @@ _set_default_imgopts()
     if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then
         IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1")
     fi
+    if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then
+        IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10")
+    fi
 }
 
 _use_sample_img()
Signature · 1 line
2.9.3
#4 lore raw

PATCH v4 4/5 iotests: add more LUKS hash combination tests

In reply to Daniel P. Berrange

Add tests for sha224, sha512, sha384 and ripemd160 hash algorithms.

---
 tests/qemu-iotests/149     |  10 +-
 tests/qemu-iotests/149.out | 482 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 484 insertions(+), 8 deletions(-)
tests/qemu-iotests/149 +4 -6
index f62e618..5faf585 100755
@@ -457,8 +457,12 @@ configs = [
 
 
     # LUKS default but diff hash
+    LUKSConfig("aes-256-xts-plain64-sha224",
+               "aes", 256, "xts", "plain64", None, "sha224"),
     LUKSConfig("aes-256-xts-plain64-sha256",
                "aes", 256, "xts", "plain64", None, "sha256"),
+    LUKSConfig("aes-256-xts-plain64-sha384",
+               "aes", 256, "xts", "plain64", None, "sha384"),
     LUKSConfig("aes-256-xts-plain64-sha512",
                "aes", 256, "xts", "plain64", None, "sha512"),
     LUKSConfig("aes-256-xts-plain64-ripemd160",
@@ -504,12 +508,6 @@ blacklist = [
 
     # GCrypt doesn't support Twofish with 192 bit key
     "twofish-192-xts-plain64-sha1",
-
-    # We don't have sha512 hash wired up yet
-    "aes-256-xts-plain64-sha512",
-
-    # We don't have ripemd160 hash wired up yet
-    "aes-256-xts-plain64-ripemd160",
 ]
 
 whitelist = []
tests/qemu-iotests/149.out +480 -2

494 lines not on this page · raw message

Signature · 1 line
2.9.3
#5 lore raw

PATCH v4 5/5 iotests: chown LUKS device before qemu-io launches

In reply to Daniel P. Berrange

On some distros, whenever you close a block device file descriptor there is a udev rule that resets the file permissions. This can race with the test script when we run qemu-io multiple times against the same block device. Occasionally the second qemu-io invocation will find udev has reset the permissions causing failure.

---
 tests/qemu-iotests/149     |  13 +-
 tests/qemu-iotests/149.out | 344 ++++++++++++++++++++++-----------------------
 2 files changed, 178 insertions(+), 179 deletions(-)
tests/qemu-iotests/149 +6 -7
index 5faf585..bc628ce 100755
@@ -23,6 +23,7 @@
 import subprocess
 import os
 import os.path
+import time
 
 import base64
 
@@ -186,7 +187,7 @@ def chown(config):
     msg = proc.communicate()[0]
 
     if proc.returncode != 0:
-        raise Exception("Cannot change owner on %s" % path)
+        raise Exception(msg)
 
 
 def cryptsetup_open(config):
@@ -271,6 +272,8 @@ def qemu_io_image_args(config, dev=False):
 def qemu_io_write_pattern(config, pattern, offset_mb, size_mb, dev=False):
     """Write a pattern of data to a LUKS image or device"""
 
+    if dev:
+        chown(config)
     args = ["-c", "write -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)]
     args.extend(qemu_io_image_args(config, dev))
     iotests.log("qemu-io " + " ".join(args), filters=[iotests.filter_test_dir])
@@ -281,6 +284,8 @@ def qemu_io_write_pattern(config, pattern, offset_mb, size_mb, dev=False):
 def qemu_io_read_pattern(config, pattern, offset_mb, size_mb, dev=False):
     """Read a pattern of data to a LUKS image or device"""
 
+    if dev:
+        chown(config)
     args = ["-c", "read -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)]
     args.extend(qemu_io_image_args(config, dev))
     iotests.log("qemu-io " + " ".join(args), filters=[iotests.filter_test_dir])
@@ -331,9 +336,6 @@ def test_once(config, qemu_img=False):
         cryptsetup_open(config)
 
         try:
-            iotests.log("# Set dev owner")
-            chown(config)
-
             iotests.log("# Write test pattern 0xa7")
             qemu_io_write_pattern(config, 0xa7, lowOffsetMB, 10, dev=True)
             iotests.log("# Write test pattern 0x13")
@@ -365,9 +367,6 @@ def test_once(config, qemu_img=False):
         cryptsetup_open(config)
 
         try:
-            iotests.log("# Set dev owner")
-            chown(config)
-
             iotests.log("# Read test pattern 0x91")
             qemu_io_read_pattern(config, 0x91, lowOffsetMB, 10, dev=True)
             iotests.log("# Read test pattern 0x5e")
tests/qemu-iotests/149.out +172 -172

1,376 lines not on this page · raw message

Signature · 1 line
2.9.3
#6 lore raw
In reply to Daniel P. Berrange

Am 02.05.2017 um 17:54 hat Daniel P. Berrange geschrieben:

Quoted 9 lines

The main goal of this series is to get the I/O tests passing 100% with LUKS when run with './check -luks'. It also adds a few more combinations to the LUKS/dmcrypt interoperability test.

To make LUKS testing not quite as slow, we drop the PBKDF iteration count down to a very small value. This doesn't remove all overhead, as formatting the volume will always measure PBKDF timing over a 1 second interval.

It looks like patch 2 needs a rebase before it can be applied to my block branch.

Kevin