From nobody Fri Oct 18 08:37:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1707487782; cv=none; d=zohomail.com; s=zohoarc; b=lYpVvPngZv0xN1vjEv42y70fD0hxHF+ncpFN6O4ph5jamLOQZvOhRTmQzDE/QZq6k9NP5KAXrcNJa0uN0a6ETCTIKJA0Zl1KeGRdHFmG0IBim5bOB6nm1/dq5dyKv0kKVRaNFnvvDBtEcMAl0TcYxyVvJLcGzYgN+iyuzDFXfpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707487782; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UOtlDkkTa3GleU1CyjlxJoIy6uWxwEwTrEVVgffK/jk=; b=neY6GXtoXE/CRS6OBb9eGnL2AxGHuFr4va5DQOqHUYumFWMe1eA3wGt7jJmk34HxZJ0Y6HLwTP+/ibEz5uWGIibSQu0ivPjJ1KXHfAX5547wCSJ2VZU/VVBX+PWzBzh/IcldzVlw3701VJmzg1tOcAIBYjv+Z/W62H7YnxE3/2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1707487782422357.4087663124898; Fri, 9 Feb 2024 06:09:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYRWN-0003st-2v; Fri, 09 Feb 2024 09:06:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rYRW1-0003NS-27 for qemu-devel@nongnu.org; Fri, 09 Feb 2024 09:06:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rYRVy-0004Pm-Iw for qemu-devel@nongnu.org; Fri, 09 Feb 2024 09:06:04 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-H9mBTrJEOf21P5i-zCvoqw-1; Fri, 09 Feb 2024 09:05:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27F831C0F47A; Fri, 9 Feb 2024 14:05:56 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id A431311217; Fri, 9 Feb 2024 14:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707487561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UOtlDkkTa3GleU1CyjlxJoIy6uWxwEwTrEVVgffK/jk=; b=AGwmqzpWklrUMUBbVdW3ceazyJZ47bZhBTAB10UOt7RVma5KUU8uI8rk+4+b8feA3Nb8Kq Tbxv/hClBcsXxbwrF3s5/iujIBxDjjuRfx3CFWnwFUSXokxSyAfuPy4ASuN5V8fm5+v9+5 SrP/Usm87lpZ0Jg8wb8K1qn8GE76aL4= X-MC-Unique: H9mBTrJEOf21P5i-zCvoqw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Cleber Rosa , Paolo Bonzini , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Stefan Weil , Kevin Wolf , Thomas Huth , Hyman Huang , Richard Henderson , John Snow , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 17/17] tests: Add case for LUKS volume with detached header Date: Fri, 9 Feb 2024 14:05:05 +0000 Message-ID: <20240209140505.2536635-18-berrange@redhat.com> In-Reply-To: <20240209140505.2536635-1-berrange@redhat.com> References: <20240209140505.2536635-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.269, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1707487783275100005 From: Hyman Huang Also, add a section to the MAINTAINERS file for detached LUKS header, it only has a test case in it currently. Signed-off-by: Hyman Huang Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 5 + tests/qemu-iotests/tests/luks-detached-header | 316 ++++++++++++++++++ .../tests/luks-detached-header.out | 5 + 3 files changed, 326 insertions(+) create mode 100755 tests/qemu-iotests/tests/luks-detached-header create mode 100644 tests/qemu-iotests/tests/luks-detached-header.out diff --git a/MAINTAINERS b/MAINTAINERS index 2f9741b898..f80db6a96a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3402,6 +3402,11 @@ F: migration/dirtyrate.c F: migration/dirtyrate.h F: include/sysemu/dirtyrate.h =20 +Detached LUKS header +M: Hyman Huang +S: Maintained +F: tests/qemu-iotests/tests/luks-detached-header + D-Bus M: Marc-Andr=C3=A9 Lureau S: Maintained diff --git a/tests/qemu-iotests/tests/luks-detached-header b/tests/qemu-iot= ests/tests/luks-detached-header new file mode 100755 index 0000000000..3455fd8de1 --- /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 +# +# 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 . +# + +import os +import json +import iotests +from iotests import ( + imgfmt, + qemu_img_create, + qemu_img_info, + QMPTestCase, +) + + +image_size =3D 128 * 1024 * 1024 + +luks_img =3D os.path.join(iotests.test_dir, "luks.img") +detached_header_img1 =3D os.path.join(iotests.test_dir, "detached_header.i= mg1") +detached_header_img2 =3D os.path.join(iotests.test_dir, "detached_header.i= mg2") +detached_payload_raw_img =3D os.path.join( + iotests.test_dir, "detached_payload_raw.img" +) +detached_payload_qcow2_img =3D os.path.join( + iotests.test_dir, "detached_payload_qcow2.img" +) +detached_header_raw_img =3D "json:" + json.dumps( + { + "driver": "luks", + "file": {"filename": detached_payload_raw_img}, + "header": { + "filename": detached_header_img1, + }, + } +) +detached_header_qcow2_img =3D "json:" + json.dumps( + { + "driver": "luks", + "file": {"filename": detached_payload_qcow2_img}, + "header": {"filename": detached_header_img2}, + } +) + +secret_obj =3D "secret,id=3Dsec0,data=3Dfoo" +luks_opts =3D "key-secret=3Dsec0" + + +class TestDetachedLUKSHeader(QMPTestCase): + def setUp(self) -> None: + self.vm =3D 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=3D"file", + filename=3Dluks_img, + node_name=3D"luks-1-storage", + ) + result =3D 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=3D"file", + filename=3Ddetached_header_img1, + node_name=3D"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=3D"file", + filename=3Ddetached_payload_raw_img, + node_name=3D"luks-2-payload-storage", + ) + + # Format LUKS disk with detached header + result =3D 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 =3D qemu_img_create( + "-f", + "luks", + "--object", + secret_obj, + "-o", + luks_opts, + "-o", + "detached-header=3Dtrue", + detached_header_img2, + ) + assert res.returncode =3D=3D 0 + + # Create detached LUKS qcow2 payload + res =3D qemu_img_create( + "-f", "qcow2", detached_payload_qcow2_img, str(image_size) + ) + assert res.returncode =3D=3D 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 =3D qemu_img_info(luks_img)["format-specific"] + self.assertEqual(data["type"], imgfmt) + self.assertEqual(data["data"]["detached-header"], False) + + data =3D qemu_img_info(detached_header_raw_img)["format-specific"] + self.assertEqual(data["type"], imgfmt) + self.assertEqual(data["data"]["detached-header"], True) + + data =3D 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 =3D 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=3D"file", + filename=3Dluks_img, + node_name=3D"luks-1-storage", + ) + result =3D self.vm.qmp_log( + "blockdev-add", + driver=3D"luks", + file=3D"luks-1-storage", + key_secret=3D"sec0", + node_name=3D"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=3D"file", + filename=3Ddetached_header_img1, + node_name=3D"luks-header1-storage", + ) + + self.vm.qmp_log( + "blockdev-add", + driver=3D"file", + filename=3Ddetached_payload_raw_img, + node_name=3D"luks-2-payload-raw-storage", + ) + + result =3D self.vm.qmp_log( + "blockdev-add", + driver=3Dimgfmt, + header=3D"luks-header1-storage", + file=3D"luks-2-payload-raw-storage", + key_secret=3D"sec0", + node_name=3D"luks-2-payload-raw-format", + ) + self.assert_qmp(result, "return", {}) + + # Add detached LUKS header with qcow2 payload + self.vm.qmp_log( + "blockdev-add", + driver=3D"file", + filename=3Ddetached_header_img2, + node_name=3D"luks-header2-storage", + ) + + self.vm.qmp_log( + "blockdev-add", + driver=3D"file", + filename=3Ddetached_payload_qcow2_img, + node_name=3D"luks-3-payload-qcow2-storage", + ) + + result =3D self.vm.qmp_log( + "blockdev-add", + driver=3Dimgfmt, + header=3D"luks-header2-storage", + file=3D"luks-3-payload-qcow2-storage", + key_secret=3D"sec0", + node_name=3D"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 =3D self.vm.qmp_log( + "human-monitor-command", + command_line=3D'qemu-io luks-1-format "write -P 40 0 64k"', + ) + self.assert_qmp(result, "return", "") + + result =3D self.vm.qmp_log( + "human-monitor-command", + command_line=3D'qemu-io luks-1-format "read -P 40 0 64k"', + ) + self.assert_qmp(result, "return", "") + + # Detached LUKS header with raw payload + cmd =3D 'qemu-io luks-2-payload-raw-format "write -P 41 0 64k"' + result =3D self.vm.qmp( + "human-monitor-command", + command_line=3Dcmd + ) + self.assert_qmp(result, "return", "") + + cmd =3D 'qemu-io luks-2-payload-raw-format "read -P 41 0 64k"' + result =3D self.vm.qmp( + "human-monitor-command", + command_line=3Dcmd + ) + self.assert_qmp(result, "return", "") + + # Detached LUKS header with qcow2 payload + cmd =3D 'qemu-io luks-3-payload-qcow2-format "write -P 42 0 64k"' + result =3D self.vm.qmp( + "human-monitor-command", + command_line=3Dcmd + ) + self.assert_qmp(result, "return", "") + + cmd =3D 'qemu-io luks-3-payload-qcow2-format "read -P 42 0 64k"' + result =3D self.vm.qmp( + "human-monitor-command", + command_line=3Dcmd + ) + self.assert_qmp(result, "return", "") + + self.vm.shutdown() + + +if __name__ =3D=3D "__main__": + # Test image creation and I/O + iotests.main(supported_fmts=3D["luks"], supported_protocols=3D["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 0000000000..fbc63e62f8 --- /dev/null +++ b/tests/qemu-iotests/tests/luks-detached-header.out @@ -0,0 +1,5 @@ +.. +---------------------------------------------------------------------- +Ran 2 tests + +OK --=20 2.43.0