From nobody Mon Feb 9 12:09:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1595887283; cv=none; d=zohomail.com; s=zohoarc; b=gfKtx5C2QRPhx9EuXyWMpDNhKmnO3ZSkI/cjZUrduzbH1sHenQn1JcKfn9zbVNUGutD8JQaUN4bElXSVxDils8rmDYmR3PusBbsUIWPzL51KmftiiqEvbJnk3VW+9ivuaA2+ANEW3ASGjpiSN/lx6zcTYsITbcMIG9vbi6UqGWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595887283; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YxkYB4mtsedDfq3OADLqoKGrrr9VRyJd5kW4UXFdOtQ=; b=N25/6fp0cYlxUs/LqK56WgLb+9CcUGVLBk4sSUukgHPNwK65VWOOl8TkCKpVMAFPAtTmOMdZnkEd6Syz6B/4OAf7Q0iW5D5xghmsc0OWUix1slIcXdCkuZZIG4Rv481xGEFXFtzxzdWCMXRVzrPqlzwAHX+igOBduIDwaLi3vMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595887283937329.15762832480414; Mon, 27 Jul 2020 15:01:23 -0700 (PDT) Received: from localhost ([::1]:57414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k0BBS-0001IR-L7 for importer@patchew.org; Mon, 27 Jul 2020 18:01:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0B9F-00083S-4i; Mon, 27 Jul 2020 17:59:05 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:39569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k0B9D-0004Ls-8s; Mon, 27 Jul 2020 17:59:04 -0400 Received: by mail-wm1-x333.google.com with SMTP id t142so9835649wmt.4; Mon, 27 Jul 2020 14:59:02 -0700 (PDT) Received: from localhost.localdomain (109-186-134-209.bb.netvision.net.il. [109.186.134.209]) by smtp.gmail.com with ESMTPSA id p14sm14492940wrx.90.2020.07.27.14.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 14:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YxkYB4mtsedDfq3OADLqoKGrrr9VRyJd5kW4UXFdOtQ=; b=BVoqSPcqpqZih8B18GX/smub9v22DY/4t+1BkGIb6gRsp6Fu3GuGP/HjLukHiHPW7e oJbBXrwx0noJvLliGkFGiYSKmn3Wz/Nw+i4soy/aw3da6Z30UAlH1p4VzUhpe/ts2l7e T2FP0vQJZn826hVzwk08dRF4RneWOajzjXYQg0O/w1KlclcD6yX7Mfgk6E6h6UAGXuc3 46FPRH8SLx0QGb7xORHN41Kt8EvhiqjtY5Avi7OAfXakd5KS7zTcVG3dK2/z4imCA06L +oJvRwGUl/EsWYY8xWtWRk6WcodiVwCMoxOfBGVqeK+7M8KSf9TdzpISraAUThZHICRl mRWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YxkYB4mtsedDfq3OADLqoKGrrr9VRyJd5kW4UXFdOtQ=; b=OQPp8hF3Z2u6C+n6zzmMGgkS/pSV8O9qAlo3rvNFZmNmtG3TR62jAf1dMI1l9V9xDV B666WSH9/l0nwkdradSWCl5v+2Rsk6SczzKzR/ReDhJLHPRQPauG1X+b2qlGzVrzIbyX xPRprJlgy+EVWu2uiil3QJR8iNojwZAg5qKp87UWTtW57dQLDbSTQ+Dvsl8yBhNdUWgL DB72T127O9V86h4hinFAYrn5B1g1zezET+J6i0Jqn6w/8TBQu8iJBDwXoBvxOZD9CaTM e0RQWPL3ZuOUsNL0NnbxDY1DrCrLiY45EgiJuA9ISjCwAjabS6m0y1ubYBECGyoME7xm Ntww== X-Gm-Message-State: AOAM531gWanmXqPSlMOUtrAaysXoedVvHC5XohttxTLEMH49HDY62q+D OrvOtMSbSrxPijYJByRwWtE90vhzxb0= X-Google-Smtp-Source: ABdhPJyikwlpDKbC++I50eFvhJjNBkQERvAavZvfWk7Dh1HFVcEpvDqnT4LGF0oMY2ZK4qvKBayEvQ== X-Received: by 2002:a1c:f219:: with SMTP id s25mr1067199wmc.2.1595887140970; Mon, 27 Jul 2020 14:59:00 -0700 (PDT) From: Nir Soffer X-Google-Original-From: Nir Soffer To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v2 4/4] iotests: Test convert to qcow2 compressed to NBD Date: Tue, 28 Jul 2020 00:58:46 +0300 Message-Id: <20200727215846.395443-5-nsoffer@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200727215846.395443-1-nsoffer@redhat.com> References: <20200727215846.395443-1-nsoffer@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::333; envelope-from=nirsof@gmail.com; helo=mail-wm1-x333.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Nir Soffer , vsementsov@virtuozzo.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add test for "qemu-img convert -O qcow2 -c" to NBD target. The tests =C2=A0= =C2=A0 create a OVA file and write compressed qcow2 disk content directly into the OVA file via qemu-nbd. Signed-off-by: Nir Soffer Reviewed-by: Eric Blake Tested-by: Eric Blake --- tests/qemu-iotests/302 | 127 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/302.out | 31 +++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 159 insertions(+) create mode 100755 tests/qemu-iotests/302 create mode 100644 tests/qemu-iotests/302.out diff --git a/tests/qemu-iotests/302 b/tests/qemu-iotests/302 new file mode 100755 index 0000000000..a8506bda15 --- /dev/null +++ b/tests/qemu-iotests/302 @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +# +# Tests converting qcow2 compressed to NBD +# +# Copyright (c) 2020 Nir Soffer +# +# 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 . +# +# owner=3Dnirsof@gmail.com + +import io +import tarfile + +import iotests + +from iotests import ( + file_path, + qemu_img, + qemu_img_check, + qemu_img_create, + qemu_img_log, + qemu_img_measure, + qemu_io, + qemu_nbd_popen, +) + +iotests.script_initialize(supported_fmts=3D["qcow2"]) + +# Create source disk. Using qcow2 to enable strict comparing later, and +# avoid issues with random filesystem on CI environment. +src_disk =3D file_path("disk.qcow2") +qemu_img_create("-f", iotests.imgfmt, src_disk, "1g") +qemu_io("-f", iotests.imgfmt, "-c", "write 1m 64k", src_disk) + +# The use case is writing qcow2 image directly into an ova file, which +# is a tar file with specific layout. This is tricky since we don't know t= he +# size of the image before compressing, so we have to do: +# 1. Add an ovf file. +# 2. Find the offset of the next member data. +# 3. Make room for image data, allocating for the worst case. +# 4. Write compressed image data into the tar. +# 5. Add a tar entry with the actual image size. +# 6. Shrink the tar to the actual size, aligned to 512 bytes. + +tar_file =3D file_path("test.ova") + +with tarfile.open(tar_file, "w") as tar: + + # 1. Add an ovf file. + + ovf_data =3D b"" + ovf =3D tarfile.TarInfo("vm.ovf") + ovf.size =3D len(ovf_data) + tar.addfile(ovf, io.BytesIO(ovf_data)) + + # 2. Find the offset of the next member data. + + offset =3D tar.fileobj.tell() + 512 + + # 3. Make room for image data, allocating for the worst case. + + measure =3D qemu_img_measure("-O", "qcow2", src_disk) + tar.fileobj.truncate(offset + measure["required"]) + + # 4. Write compressed image data into the tar. + + nbd_sock =3D file_path("nbd-sock", base_dir=3Diotests.sock_dir) + nbd_uri =3D "nbd+unix:///exp?socket=3D" + nbd_sock + + # Use raw format to allow creating qcow2 directly into tar file. + with qemu_nbd_popen( + "--socket", nbd_sock, + "--export-name", "exp", + "--format", "raw", + "--offset", str(offset), + tar_file): + + iotests.log("=3D=3D=3D Target image info =3D=3D=3D") + qemu_img_log("info", nbd_uri) + + qemu_img( + "convert", + "-f", iotests.imgfmt, + "-O", "qcow2", + "-c", + src_disk, + nbd_uri) + + iotests.log("=3D=3D=3D Converted image info =3D=3D=3D") + qemu_img_log("info", nbd_uri) + + iotests.log("=3D=3D=3D Converted image check =3D=3D=3D") + qemu_img_log("check", nbd_uri) + + iotests.log("=3D=3D=3D Comparing to source disk =3D=3D=3D") + qemu_img_log("compare", src_disk, nbd_uri) + + actual_size =3D qemu_img_check(nbd_uri)["image-end-offset"] + + # 5. Add a tar entry with the actual image size. + + disk =3D tarfile.TarInfo("disk") + disk.size =3D actual_size + tar.addfile(disk) + + # 6. Shrink the tar to the actual size, aligned to 512 bytes. + + tar_size =3D offset + (disk.size + 511) & ~511 + tar.fileobj.seek(tar_size) + tar.fileobj.truncate(tar_size) + +with tarfile.open(tar_file) as tar: + members =3D [{"name": m.name, "size": m.size, "offset": m.offset_data} + for m in tar] + iotests.log("=3D=3D=3D OVA file contents =3D=3D=3D") + iotests.log(members) diff --git a/tests/qemu-iotests/302.out b/tests/qemu-iotests/302.out new file mode 100644 index 0000000000..e37d3a1030 --- /dev/null +++ b/tests/qemu-iotests/302.out @@ -0,0 +1,31 @@ +Start NBD server +=3D=3D=3D Target image info =3D=3D=3D +image: nbd+unix:///exp?socket=3DSOCK_DIR/PID-nbd-sock +file format: raw +virtual size: 448 KiB (458752 bytes) +disk size: unavailable + +=3D=3D=3D Converted image info =3D=3D=3D +image: nbd+unix:///exp?socket=3DSOCK_DIR/PID-nbd-sock +file format: qcow2 +virtual size: 1 GiB (1073741824 bytes) +disk size: unavailable +cluster_size: 65536 +Format specific information: + compat: 1.1 + compression type: zlib + lazy refcounts: false + refcount bits: 16 + corrupt: false + +=3D=3D=3D Converted image check =3D=3D=3D +No errors were found on the image. +1/16384 =3D 0.01% allocated, 100.00% fragmented, 100.00% compressed cluste= rs +Image end offset: 393216 + +=3D=3D=3D Comparing to source disk =3D=3D=3D +Images are identical. + +Kill NBD server +=3D=3D=3D OVA file contents =3D=3D=3D +[{"name": "vm.ovf", "offset": 512, "size": 6}, {"name": "disk", "offset": = 1536, "size": 393216}] diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 1d0252e1f0..1e1cb27bc8 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -308,3 +308,4 @@ 297 meta 299 auto quick 301 backing quick +302 quick --=20 2.25.4