From patchwork Tue Apr 11 01:17:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9674435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BBF3B6020C for ; Tue, 11 Apr 2017 01:19:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAD7A283E1 for ; Tue, 11 Apr 2017 01:19:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FAC0284DD; Tue, 11 Apr 2017 01:19:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DD100283E1 for ; Tue, 11 Apr 2017 01:19:38 +0000 (UTC) Received: from localhost ([::1]:36686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxkT3-0005sw-VN for patchwork-qemu-devel@patchwork.kernel.org; Mon, 10 Apr 2017 21:19:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxkR6-0005HI-AI for qemu-devel@nongnu.org; Mon, 10 Apr 2017 21:17:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxkR4-0005px-E9 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 21:17:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cxkQy-0005n9-P5; Mon, 10 Apr 2017 21:17:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C482C80461; Tue, 11 Apr 2017 01:17:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C482C80461 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C482C80461 Received: from red.redhat.com (ovpn-122-58.rdu2.redhat.com [10.10.122.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id E355C78DF2; Tue, 11 Apr 2017 01:17:26 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 10 Apr 2017 20:17:07 -0500 Message-Id: <20170411011718.9152-3-eblake@redhat.com> In-Reply-To: <20170411011718.9152-1-eblake@redhat.com> References: <20170411011718.9152-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 11 Apr 2017 01:17:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 02/13] iotests: Add test 179 to cover write zeroes with unmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP No tests were covering write zeroes with unmap. Additionally, I wanted to prove that my patch to optimize write zeroes for compat=0.10 images actually had an impact; for that, run: ./check -qcow2 -o compat=0.10 179 Writing the test to work correctly for both old and new qcow2 images is a bit tricky: 'qemu-img map' works for showing whether a cluster is assigned an offset (in the preallocation sense), but older images have to write literal zeroes where newer images can set the zero flag. Thankfully, 'qemu-io alloc' hides the difference, by instead reporting whether a cluster's content comes from the current layer (regardless of whether it was due to a cluster allocation or a flag). Signed-off-by: Eric Blake --- tests/qemu-iotests/179 | 78 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/179.out | 22 +++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 101 insertions(+) create mode 100755 tests/qemu-iotests/179 create mode 100644 tests/qemu-iotests/179.out diff --git a/tests/qemu-iotests/179 b/tests/qemu-iotests/179 new file mode 100755 index 0000000..338a45d --- /dev/null +++ b/tests/qemu-iotests/179 @@ -0,0 +1,78 @@ +#!/bin/bash +# +# Test case for write zeroes with unmap +# +# Copyright (C) 2017 Red Hat, Inc. +# +# 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 . +# + +# creator +owner=eblake@redhat.com + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +echo +echo '=== Testing write zeroes with unmap ===' +echo + +TEST_IMG="$TEST_IMG.base" _make_test_img 16M +_make_test_img -b "$TEST_IMG.base" + +# Aligned writes should not allocate clusters, if unmap is requested +# and there is no backing file. +$QEMU_IO -c "write -z -u 1M 1M" "$TEST_IMG.base" | _filter_qemu_io + +# Unmap can even clear previously-allocated clusters. +$QEMU_IO -c "write 3M 1M" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z -u 3M 1M" "$TEST_IMG.base" | _filter_qemu_io + +# Up to now, the entire image should still be unallocated. +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +# But not requesting unmap must result in allocation (whether a cluster +# allocation in compat=0.10 or a flag allocation in compat=1.1). +$QEMU_IO -c "write -z 5M 1M" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "alloc 5M $((1024*1024 / 512))" "$TEST_IMG.base" | _filter_qemu_io + +# Presence of a backing file overrides permission to unmap. Again, +# compat=0.10 images allocate, while compat=1.1 images set zero flag. +$QEMU_IO -c "write -z -u 7M 1M" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "alloc 7M $((1024 * 1024 / 512))" "$TEST_IMG" | _filter_qemu_io + +# Final check that images are still sane. +TEST_IMG="$TEST_IMG.base" _check_test_img +_check_test_img + +# success, all done +echo '*** done' +status=0 diff --git a/tests/qemu-iotests/179.out b/tests/qemu-iotests/179.out new file mode 100644 index 0000000..fc97b19 --- /dev/null +++ b/tests/qemu-iotests/179.out @@ -0,0 +1,22 @@ +QA output created by 179 + +=== Testing write zeroes with unmap === + +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=16777216 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=16777216 backing_file=TEST_DIR/t.IMGFMT.base +wrote 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +[{ "start": 0, "length": 16777216, "depth": 1, "zero": true, "data": false}] +wrote 1048576/1048576 bytes at offset 5242880 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +2048/2048 sectors allocated at offset 5 MiB +wrote 1048576/1048576 bytes at offset 7340032 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +2048/2048 sectors allocated at offset 7 MiB +No errors were found on the image. +No errors were found on the image. +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 43142dd..cfc8823 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -169,3 +169,4 @@ 174 auto 175 auto quick 176 rw auto backing +179 rw auto quick