aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2024-02-12 14:13:58 +0000
committerPeter Maydell <peter.maydell@linaro.org>2024-02-12 14:13:58 +0000
commit15dbbeaff3c696be8c9c236ffb25d25ce21cba38 (patch)
tree3c37da4ba9751d3f8ccf7f7da31f931caa7bf54b /tests/qemu-iotests
parentdf50424b4dcfde823047d3717abd6a61224ea205 (diff)
parentd87b258b75498d3e8563ec8ebaaf67efc27be945 (diff)
downloadqemu-15dbbeaff3c696be8c9c236ffb25d25ce21cba38.zip
qemu-15dbbeaff3c696be8c9c236ffb25d25ce21cba38.tar.gz
qemu-15dbbeaff3c696be8c9c236ffb25d25ce21cba38.tar.bz2
Merge tag 'misc-fixes-pull-request' of https://gitlab.com/berrange/qemu into staging
- LUKS support for detached headers - Update x86 CPU model docs and script - Add missing close of chardev QIOChannel - More trace events o nTKS handshake - Drop unsafe VNC constants - Increase NOFILE limit during startup # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEE2vOm/bJrYpEtDo4/vobrtBUQT98FAmXGMNUACgkQvobrtBUQ # T998JQ//SqQ3L/AZmhE5cIwZ1XipSMMZ/yEoVIyniA3tL41S7Oimj3O9XvY68TEG # nnj9Oh+zOlVLxauTHAczveJ7z+XfonQZS3HrbGRUTHU+ezGVjyM618e/h9pSQtYI # +CCkrjtey1NoT42/um4D/bKg/B2XQeulS+pD12Z9l5zbqEZiw0R9+UwVIJ52G811 # 5UQgIjJ7GNFzalxqiMCkGc0nTyU8keEXQJcdZ4droo42DnU4pZeQWGDimzP61JnW # 1Crm6aZSuUriUbVmxJde+2eEdPSR4rr/yQ4Pw06hoi1QJALSgGYtOTo8+qsyumHd # us/2ouMrxOMdsIk4ViAkSTiaje9agPj84VE1Z229Y/uqZcEAuX572n730/kkzqUv # ZDKxMz0v3rzpkjFmsgj5D4yqJaQp4zn1zYm98ld7HWJVIOf3GSvpaNg9J6jwN7Gi # HKKkvYns9pxg3OSx++gqnM32HV6nnMDFiddipl/hTiUsnNlnWyTDSvJoNxIUU5+l # /uEbbdt8xnxx1JP0LiOhgmz6N6FU7oOpaPuJ5CD8xO2RO8D1uBRvmpFcdOTDAfv0 # uYdjhKBI+quKjE64p7gNWYCoqZtipRIJ6AY2VaPU8XHx8GvGFwBLX64oLYiYtrBG # gkv3NTHRkMhQw9cGQcZIgZ+OLU+1eNF+m9EV7LUjuKl0HWC3Vjs= # =61zI # -----END PGP SIGNATURE----- # gpg: Signature made Fri 09 Feb 2024 14:04:05 GMT # gpg: using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF # gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full] # gpg: aka "Daniel P. Berrange <berrange@redhat.com>" [full] # Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF * tag 'misc-fixes-pull-request' of https://gitlab.com/berrange/qemu: tests: Add case for LUKS volume with detached header crypto: Introduce 'detached-header' field in QCryptoBlockInfoLUKS block: Support detached LUKS header creation using qemu-img block: Support detached LUKS header creation using blockdev-create crypto: Modify the qcrypto_block_create to support creation flags qapi: Make parameter 'file' optional for BlockdevCreateOptionsLUKS crypto: Support LUKS volume with detached header io: add trace event when cancelling TLS handshake chardev: close QIOChannel before unref'ing docs: re-generate x86_64 ABI compatibility CSV docs: fix highlighting of CPU ABI header rows scripts: drop comment about autogenerated CPU API file softmmu: remove obsolete comment about libvirt timeouts ui: drop VNC feature _MASK constants qemu_init: increase NOFILE soft limit on POSIX crypto: Introduce SM4 symmetric cipher algorithm meson: sort C warning flags alphabetically Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/qemu-iotests')
-rw-r--r--tests/qemu-iotests/210.out4
-rwxr-xr-xtests/qemu-iotests/tests/luks-detached-header316
-rw-r--r--tests/qemu-iotests/tests/luks-detached-header.out5
3 files changed, 325 insertions, 0 deletions
diff --git a/tests/qemu-iotests/210.out b/tests/qemu-iotests/210.out
index 96d9f74..94b29b2 100644
--- a/tests/qemu-iotests/210.out
+++ b/tests/qemu-iotests/210.out
@@ -18,6 +18,7 @@ virtual size: 128 MiB (134217728 bytes)
encrypted: yes
Format specific information:
ivgen alg: plain64
+ detached header: false
hash alg: sha256
cipher alg: aes-256
uuid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -70,6 +71,7 @@ virtual size: 64 MiB (67108864 bytes)
encrypted: yes
Format specific information:
ivgen alg: plain64
+ detached header: false
hash alg: sha1
cipher alg: aes-128
uuid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -125,6 +127,7 @@ virtual size: 0 B (0 bytes)
encrypted: yes
Format specific information:
ivgen alg: plain64
+ detached header: false
hash alg: sha256
cipher alg: aes-256
uuid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -195,6 +198,7 @@ virtual size: 0 B (0 bytes)
encrypted: yes
Format specific information:
ivgen alg: plain64
+ detached header: false
hash alg: sha256
cipher alg: aes-256
uuid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
diff --git a/tests/qemu-iotests/tests/luks-detached-header b/tests/qemu-iotests/tests/luks-detached-header
new file mode 100755
index 0000000..3455fd8
--- /dev/null
+++ b/tests/qemu-iotests/tests/luks-detached-header
@@ -0,0 +1,316 @@
+#!/usr/bin/env python3
+# group: rw auto
+#
+# Test LUKS volume with detached header
+#
+# Copyright (C) 2024 SmartX Inc.
+#
+# Authors:
+# Hyman Huang <yong.huang@smartx.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import os
+import json
+import iotests
+from iotests import (
+ imgfmt,
+ qemu_img_create,
+ qemu_img_info,
+ QMPTestCase,
+)
+
+
+image_size = 128 * 1024 * 1024
+
+luks_img = os.path.join(iotests.test_dir, "luks.img")
+detached_header_img1 = os.path.join(iotests.test_dir, "detached_header.img1")
+detached_header_img2 = os.path.join(iotests.test_dir, "detached_header.img2")
+detached_payload_raw_img = os.path.join(
+ iotests.test_dir, "detached_payload_raw.img"
+)
+detached_payload_qcow2_img = os.path.join(
+ iotests.test_dir, "detached_payload_qcow2.img"
+)
+detached_header_raw_img = "json:" + json.dumps(
+ {
+ "driver": "luks",
+ "file": {"filename": detached_payload_raw_img},
+ "header": {
+ "filename": detached_header_img1,
+ },
+ }
+)
+detached_header_qcow2_img = "json:" + json.dumps(
+ {
+ "driver": "luks",
+ "file": {"filename": detached_payload_qcow2_img},
+ "header": {"filename": detached_header_img2},
+ }
+)
+
+secret_obj = "secret,id=sec0,data=foo"
+luks_opts = "key-secret=sec0"
+
+
+class TestDetachedLUKSHeader(QMPTestCase):
+ def setUp(self) -> None:
+ self.vm = iotests.VM()
+ self.vm.add_object(secret_obj)
+ self.vm.launch()
+
+ # 1. Create the normal LUKS disk with 128M size
+ self.vm.blockdev_create(
+ {"driver": "file", "filename": luks_img, "size": 0}
+ )
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=luks_img,
+ node_name="luks-1-storage",
+ )
+ result = self.vm.blockdev_create(
+ {
+ "driver": imgfmt,
+ "file": "luks-1-storage",
+ "key-secret": "sec0",
+ "size": image_size,
+ "iter-time": 10,
+ }
+ )
+ # None is expected
+ self.assertEqual(result, None)
+
+ # 2. Create the LUKS disk with detached header (raw)
+
+ # Create detached LUKS header
+ self.vm.blockdev_create(
+ {"driver": "file", "filename": detached_header_img1, "size": 0}
+ )
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=detached_header_img1,
+ node_name="luks-2-header-storage",
+ )
+
+ # Create detached LUKS raw payload
+ self.vm.blockdev_create(
+ {"driver": "file", "filename": detached_payload_raw_img, "size": 0}
+ )
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=detached_payload_raw_img,
+ node_name="luks-2-payload-storage",
+ )
+
+ # Format LUKS disk with detached header
+ result = self.vm.blockdev_create(
+ {
+ "driver": imgfmt,
+ "header": "luks-2-header-storage",
+ "file": "luks-2-payload-storage",
+ "key-secret": "sec0",
+ "preallocation": "full",
+ "size": image_size,
+ "iter-time": 10,
+ }
+ )
+ self.assertEqual(result, None)
+
+ self.vm.shutdown()
+
+ # 3. Create the LUKS disk with detached header (qcow2)
+
+ # Create detached LUKS header using qemu-img
+ res = qemu_img_create(
+ "-f",
+ "luks",
+ "--object",
+ secret_obj,
+ "-o",
+ luks_opts,
+ "-o",
+ "detached-header=true",
+ detached_header_img2,
+ )
+ assert res.returncode == 0
+
+ # Create detached LUKS qcow2 payload
+ res = qemu_img_create(
+ "-f", "qcow2", detached_payload_qcow2_img, str(image_size)
+ )
+ assert res.returncode == 0
+
+ def tearDown(self) -> None:
+ os.remove(luks_img)
+ os.remove(detached_header_img1)
+ os.remove(detached_header_img2)
+ os.remove(detached_payload_raw_img)
+ os.remove(detached_payload_qcow2_img)
+
+ # Check if there was any qemu-io run that failed
+ if "Pattern verification failed" in self.vm.get_log():
+ print("ERROR: Pattern verification failed:")
+ print(self.vm.get_log())
+ self.fail("qemu-io pattern verification failed")
+
+ def test_img_creation(self) -> None:
+ # Check if the images created above are expected
+
+ data = qemu_img_info(luks_img)["format-specific"]
+ self.assertEqual(data["type"], imgfmt)
+ self.assertEqual(data["data"]["detached-header"], False)
+
+ data = qemu_img_info(detached_header_raw_img)["format-specific"]
+ self.assertEqual(data["type"], imgfmt)
+ self.assertEqual(data["data"]["detached-header"], True)
+
+ data = qemu_img_info(detached_header_qcow2_img)["format-specific"]
+ self.assertEqual(data["type"], imgfmt)
+ self.assertEqual(data["data"]["detached-header"], True)
+
+ # Check if preallocation works
+ size = qemu_img_info(detached_payload_raw_img)["actual-size"]
+ self.assertGreaterEqual(size, image_size)
+
+ def test_detached_luks_header(self) -> None:
+ self.vm.launch()
+
+ # 1. Add the disk created above
+
+ # Add normal LUKS disk
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=luks_img,
+ node_name="luks-1-storage",
+ )
+ result = self.vm.qmp_log(
+ "blockdev-add",
+ driver="luks",
+ file="luks-1-storage",
+ key_secret="sec0",
+ node_name="luks-1-format",
+ )
+
+ # Expected result{ "return": {} }
+ self.assert_qmp(result, "return", {})
+
+ # Add detached LUKS header with raw payload
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=detached_header_img1,
+ node_name="luks-header1-storage",
+ )
+
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=detached_payload_raw_img,
+ node_name="luks-2-payload-raw-storage",
+ )
+
+ result = self.vm.qmp_log(
+ "blockdev-add",
+ driver=imgfmt,
+ header="luks-header1-storage",
+ file="luks-2-payload-raw-storage",
+ key_secret="sec0",
+ node_name="luks-2-payload-raw-format",
+ )
+ self.assert_qmp(result, "return", {})
+
+ # Add detached LUKS header with qcow2 payload
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=detached_header_img2,
+ node_name="luks-header2-storage",
+ )
+
+ self.vm.qmp_log(
+ "blockdev-add",
+ driver="file",
+ filename=detached_payload_qcow2_img,
+ node_name="luks-3-payload-qcow2-storage",
+ )
+
+ result = self.vm.qmp_log(
+ "blockdev-add",
+ driver=imgfmt,
+ header="luks-header2-storage",
+ file="luks-3-payload-qcow2-storage",
+ key_secret="sec0",
+ node_name="luks-3-payload-qcow2-format",
+ )
+ self.assert_qmp(result, "return", {})
+
+ # 2. Do I/O test
+
+ # Do some I/O to the image to see whether it still works
+ # (Pattern verification will be checked by tearDown())
+
+ # Normal LUKS disk
+ result = self.vm.qmp_log(
+ "human-monitor-command",
+ command_line='qemu-io luks-1-format "write -P 40 0 64k"',
+ )
+ self.assert_qmp(result, "return", "")
+
+ result = self.vm.qmp_log(
+ "human-monitor-command",
+ command_line='qemu-io luks-1-format "read -P 40 0 64k"',
+ )
+ self.assert_qmp(result, "return", "")
+
+ # Detached LUKS header with raw payload
+ cmd = 'qemu-io luks-2-payload-raw-format "write -P 41 0 64k"'
+ result = self.vm.qmp(
+ "human-monitor-command",
+ command_line=cmd
+ )
+ self.assert_qmp(result, "return", "")
+
+ cmd = 'qemu-io luks-2-payload-raw-format "read -P 41 0 64k"'
+ result = self.vm.qmp(
+ "human-monitor-command",
+ command_line=cmd
+ )
+ self.assert_qmp(result, "return", "")
+
+ # Detached LUKS header with qcow2 payload
+ cmd = 'qemu-io luks-3-payload-qcow2-format "write -P 42 0 64k"'
+ result = self.vm.qmp(
+ "human-monitor-command",
+ command_line=cmd
+ )
+ self.assert_qmp(result, "return", "")
+
+ cmd = 'qemu-io luks-3-payload-qcow2-format "read -P 42 0 64k"'
+ result = self.vm.qmp(
+ "human-monitor-command",
+ command_line=cmd
+ )
+ self.assert_qmp(result, "return", "")
+
+ self.vm.shutdown()
+
+
+if __name__ == "__main__":
+ # Test image creation and I/O
+ iotests.main(supported_fmts=["luks"], supported_protocols=["file"])
diff --git a/tests/qemu-iotests/tests/luks-detached-header.out b/tests/qemu-iotests/tests/luks-detached-header.out
new file mode 100644
index 0000000..fbc63e6
--- /dev/null
+++ b/tests/qemu-iotests/tests/luks-detached-header.out
@@ -0,0 +1,5 @@
+..
+----------------------------------------------------------------------
+Ran 2 tests
+
+OK