From nobody Tue May 7 17:18:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1555495871; cv=none; d=zoho.com; s=zohoarc; b=Kp5yxXIXO+smDJRoDebDnjNQIpAaeypCwcW3/e8gEEka3LsOaNmsSLvD+tRDz9zp+qEPeR0yNaVPr/iNR2qmx3Woii2crxJVg650U0uvsdfTeBUFSEdvqG7l+0Xtsr8i8cRDhQZn1EiHAFPQUU5h8Pusy7E1b68jiQS/awqKyqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555495871; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=G4UBdq+6MXre6naIuj5tPcmxi9pOVsSqLhI1hPipEno=; b=k8VOIuEyycQyP67A1Ypr26xIKQ/o0xyGnb5MG3hzDgDnNfycguxKlsSagcOgIsM3p72iyMnJB9drr9yBMezgU7xsubaHhpn+q0mImsrX0d+0YaYp+y64/xC/oQ2akd/zS9mnVaQgeXf8x7WlLWXxBMaMdl/3RoIgqqKrEHvBQbQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1555495870842879.7066352056074; Wed, 17 Apr 2019 03:11:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:50032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGhWv-0003r8-Ny for importer@patchew.org; Wed, 17 Apr 2019 06:11:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGhVX-00038M-Rg for qemu-devel@nongnu.org; Wed, 17 Apr 2019 06:09:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGhVW-0003tq-Oa for qemu-devel@nongnu.org; Wed, 17 Apr 2019 06:09:35 -0400 Received: from relay.sw.ru ([185.231.240.75]:47106) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGhVW-0003st-F8; Wed, 17 Apr 2019 06:09:34 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hGhVS-0005Kr-GB; Wed, 17 Apr 2019 13:09:30 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Apr 2019 13:09:28 +0300 Message-Id: <20190417100929.39943-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190417100929.39943-1-vsementsov@virtuozzo.com> References: <20190417100929.39943-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/2] block/io: bdrv_pdiscard: support int64_t bytes parameter 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, fam@euphon.net, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes at least one overflow in qcow2_process_discards. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block.h | 4 ++-- block/io.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index c7a26199aa..69fa18867e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -432,8 +432,8 @@ void bdrv_drain_all(void); AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes); -int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes); +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); +int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); diff --git a/block/io.c b/block/io.c index dfc153b8d8..c6429380e8 100644 --- a/block/io.c +++ b/block/io.c @@ -2653,7 +2653,7 @@ int bdrv_flush(BlockDriverState *bs) typedef struct DiscardCo { BdrvChild *child; int64_t offset; - int bytes; + int64_t bytes; int ret; } DiscardCo; static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) @@ -2664,14 +2664,15 @@ static void coroutine_fn bdrv_pdiscard_co_entry(voi= d *opaque) aio_wait_kick(); } =20 -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int by= tes) +int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes) { BdrvTrackedRequest req; int max_pdiscard, ret; int head, tail, align; BlockDriverState *bs =3D child->bs; =20 - if (!bs || !bs->drv) { + if (!bs || !bs->drv || !bdrv_is_inserted(bs)) { return -ENOMEDIUM; } =20 @@ -2679,9 +2680,8 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int bytes) return -EPERM; } =20 - ret =3D bdrv_check_byte_request(bs, offset, bytes); - if (ret < 0) { - return ret; + if (offset < 0) { + return -EIO; } =20 /* Do nothing if disabled. */ @@ -2711,12 +2711,13 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child,= int64_t offset, int bytes) goto out; } =20 - max_pdiscard =3D QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_pdiscard, INT= _MAX), + max_pdiscard =3D QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_pdiscard, + BDRV_REQUEST_MAX_BYTES), align); assert(max_pdiscard >=3D bs->bl.request_alignment); =20 while (bytes > 0) { - int num =3D bytes; + int64_t num =3D bytes; =20 if (head) { /* Make small requests to get to alignment boundaries. */ @@ -2778,7 +2779,7 @@ out: return ret; } =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes) +int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { Coroutine *co; DiscardCo rwco =3D { --=20 2.18.0 From nobody Tue May 7 17:18:01 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1555495967; cv=none; d=zoho.com; s=zohoarc; b=Nqletqx45Au54PuSTb8lrCVeUFuc1Zv9myTNBZmppIVl/9g8ExfyKIOmCaomsP6I9f6Zhg5DcbI9lyh1fEhupX7e+54zVKPGw2BpT5exVOBvC6vcmesEN7GIQTkgtcjkclhUPM9e/rbbQu/E6YOhfNBOhi2OGBDKRtjK55dEIv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555495967; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Ta91m8qC3Ajr1p7hx7GPE0HbMA7wA/KUP46nUkCgeDQ=; b=nf5DKROC7FckK14tahXPyPFzCxG1GdySLg/eLVoU1vdEQfHXBwkC2mgPZ69cIFNroRESC9KCGmUuKVMuCGmxiJ4fCf8kzcq9b5E7f8xBl9D1X9LjE1KDmTjVivernPkLJHH4fWQCKSV4aH8c6ZZ8SvSyLgRB9BWX9HJ8F8pelPQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) 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 1555495967257833.9354166791109; Wed, 17 Apr 2019 03:12:47 -0700 (PDT) Received: from localhost ([127.0.0.1]:50053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGhYM-0004ul-Nh for importer@patchew.org; Wed, 17 Apr 2019 06:12:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGhVY-00038N-1Z for qemu-devel@nongnu.org; Wed, 17 Apr 2019 06:09:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGhVW-0003u4-Pz for qemu-devel@nongnu.org; Wed, 17 Apr 2019 06:09:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:47100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGhVW-0003sv-F4; Wed, 17 Apr 2019 06:09:34 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hGhVS-0005Kr-MR; Wed, 17 Apr 2019 13:09:30 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Apr 2019 13:09:29 +0300 Message-Id: <20190417100929.39943-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190417100929.39943-1-vsementsov@virtuozzo.com> References: <20190417100929.39943-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/2] iotests: test big qcow2 shrink 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, fam@euphon.net, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/249 | 69 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/249.out | 30 +++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 100 insertions(+) create mode 100755 tests/qemu-iotests/249 create mode 100644 tests/qemu-iotests/249.out diff --git a/tests/qemu-iotests/249 b/tests/qemu-iotests/249 new file mode 100755 index 0000000000..f0140461ad --- /dev/null +++ b/tests/qemu-iotests/249 @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +# Test big discard in qcow2 shrink +# +# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. +# +# 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=3Dvsementsov@virtuozzo.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # 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 + +# Requires backing files and .bdrv_change_backing_file support +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +# This test checks bug in qcow2_process_discards, fixed by previous commit. +# The problem was that bdrv_pdiscard was called with uint64_t bytes parame= ter +# which was cropped to int. +# To reproduce bug we need to overflow int by one sequential discard, so we +# need size > 2G, bigger cluster size (as with default 64k we may have max= imum +# of 512M sequential data, corresponding to one L1 entry, and we need to w= rite +# at offset 0 at last, to prevent bdrv_co_truncate(bs->file) in +# qcow2_co_truncate to stole the whole effect of failed discard. + +size=3D2300M +IMGOPTS=3D"cluster_size=3D1M" + +_make_test_img $size +$QEMU_IO -c 'write 100M 2000M' -c 'write 2100M 200M' \ + -c 'write 0 100M' "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG info "$TEST_IMG" | _filter_testdir + +$QEMU_IMG resize --shrink "$TEST_IMG" 50M + +$QEMU_IMG info "$TEST_IMG" | _filter_testdir + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/249.out b/tests/qemu-iotests/249.out new file mode 100644 index 0000000000..18bf7b2fb2 --- /dev/null +++ b/tests/qemu-iotests/249.out @@ -0,0 +1,30 @@ +QA output created by 249 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2411724800 +wrote 2097152000/2097152000 bytes at offset 104857600 +1.953 GiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 209715200/209715200 bytes at offset 2202009600 +200 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 104857600/104857600 bytes at offset 0 +100 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +image: TEST_DIR/t.qcow2 +file format: qcow2 +virtual size: 2.2G (2411724800 bytes) +disk size: 2.3G +cluster_size: 1048576 +Format specific information: + compat: 1.1 + lazy refcounts: false + refcount bits: 16 + corrupt: false +Image resized. +image: TEST_DIR/t.qcow2 +file format: qcow2 +virtual size: 50M (52428800 bytes) +disk size: 54M +cluster_size: 1048576 +Format specific information: + compat: 1.1 + lazy refcounts: false + refcount bits: 16 + corrupt: false +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index bae7718380..3a40dbfe69 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -248,3 +248,4 @@ 246 rw auto quick 247 rw auto quick 248 rw auto quick +249 rw auto --=20 2.18.0