From nobody Mon Apr 29 17:32:25 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566491297; cv=none; d=zoho.com; s=zohoarc; b=USZO94td8pHbDyX01ZUahr+7UCSJlLU/38U5VjmyAvzU6TsfIPVnJ3CcKDZhrqN6QqL6F+Ge9f53QwtIk/vOrrcLw9mlatm6GHre7vasgikNyUyMhsNs0Ix/QhIpkkPOJbi3HbNRnBitEcUbuoMI6vZl4lJD0nCmtUE/U5kDPiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566491297; 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:ARC-Authentication-Results; bh=PvV1cD4LvoFR4n20NwQzRAQ9gZv4lB6eNjyoB6fygpk=; b=dknJlMj5VIvH+AF7yiOWi/QdutjRp7+JFtPXv8d7n/UQGqWcXrRd0LbPiBsDgiIwPHIonsTyWENGPl4XunbKjRiDMxPBFkE0QE7P2Zd7JHmihF6UXWtIeyCDobGkQ3VCms9rcFFUtzA9VHg0Hmqj3u4qT8lpKk0A/jXzIC4vgeQ= 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 1566491297386228.57429965791823; Thu, 22 Aug 2019 09:28:17 -0700 (PDT) Received: from localhost ([::1]:45518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0pwa-0002DU-Pg for importer@patchew.org; Thu, 22 Aug 2019 12:28:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40925) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0pv4-0001Bg-LA for qemu-devel@nongnu.org; Thu, 22 Aug 2019 12:26:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0pv2-0001Aq-2V for qemu-devel@nongnu.org; Thu, 22 Aug 2019 12:26:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0puv-00014D-4C; Thu, 22 Aug 2019 12:26:30 -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 79DED3083362; Thu, 22 Aug 2019 16:26:23 +0000 (UTC) Received: from localhost (unknown [10.40.205.206]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12D386114F; Thu, 22 Aug 2019 16:26:22 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 22 Aug 2019 18:26:17 +0200 Message-Id: <20190822162618.27670-2-mreitz@redhat.com> In-Reply-To: <20190822162618.27670-1-mreitz@redhat.com> References: <20190822162618.27670-1-mreitz@redhat.com> MIME-Version: 1.0 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.44]); Thu, 22 Aug 2019 16:26:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] block/file-posix: Fix xfs_write_zeroes() 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 , =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Calling ftruncate() in xfs_write_zeroes() is dangerous because it may yield and then discard data that parallel write requests have written past the old EOF in the meantime. We must not use it here. Instead, return -ENOTSUP and let the more generic fallocate code handle writing zeroes past the EOF. Reported-by: Luk=C3=A1=C5=A1 Doktor Fixes: 50ba5b2d994853b38fed10e0841b119da0f8b8e5 Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Reviewed-by: Anton Nefedov Tested-by: Luk=C3=A1=C5=A1 Doktor --- block/file-posix.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index fbeb0068db..b49e0784a4 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1472,10 +1472,13 @@ static int xfs_write_zeroes(BDRVRawState *s, int64_= t offset, uint64_t bytes) } =20 if (offset + bytes > len) { - /* XFS_IOC_ZERO_RANGE does not increase the file length */ - if (ftruncate(s->fd, offset + bytes) < 0) { - return -errno; - } + /* + * XFS_IOC_ZERO_RANGE does not increase the file length, but + * the caller probably wants us to. + * Calling ftruncate() would not be safe, so let the generic + * implementation handle this case. + */ + return -ENOTSUP; } =20 memset(&fl, 0, sizeof(fl)); @@ -1580,7 +1583,10 @@ static int handle_aiocb_write_zeroes(void *opaque) =20 #ifdef CONFIG_XFS if (s->is_xfs) { - return xfs_write_zeroes(s, aiocb->aio_offset, aiocb->aio_nbytes); + int ret =3D xfs_write_zeroes(s, aiocb->aio_offset, aiocb->aio_nbyt= es); + if (ret !=3D -ENOTSUP) { + return ret; + } } #endif =20 --=20 2.21.0 From nobody Mon Apr 29 17:32:25 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566491563; cv=none; d=zoho.com; s=zohoarc; b=hhl7+58Rlbqz7BtHLSg/3valsb+1x8L1mM2s48AX8ccHihmfUyZA/EH2+DJA4HqmEuIoKVd4/4akPdOqLs6bGsJ8J2YLdAWBT1ttVDa8yXHIsZe9q1etctErUvUPRZKZpn1Oc7tWlsvINPKNukMU8DCV5LzYiplL+tDOB0x709Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566491563; h=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:ARC-Authentication-Results; bh=iX6Kz07uc6OUVSIiLbBvwqQWQHrxhjt2ScgLCIXj5ys=; b=OBtGLUjPxbF1lDBtgLBM4n+Q51Ut+jJej+gdtyer/PDgmpDdUcVn7IRaEU2MPLJuaBLKvmGdclt0DhgDY3OJYUoezV1tXNRwArikZ37E+m61jXFlPJIS88/HYJ+K0E2rqi1rQmZHIbkFZcaAHwXGTWC1s1VQpDJy2lF7CmEy3MQ= 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 1566491563738765.1152929989055; Thu, 22 Aug 2019 09:32:43 -0700 (PDT) Received: from localhost ([::1]:45598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0q0w-00055u-DV for importer@patchew.org; Thu, 22 Aug 2019 12:32:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40955) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0pv7-0001FA-Bs for qemu-devel@nongnu.org; Thu, 22 Aug 2019 12:26:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0pv4-0001Ck-Ri for qemu-devel@nongnu.org; Thu, 22 Aug 2019 12:26:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0puw-00015K-Fo; Thu, 22 Aug 2019 12:26:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA1333082D9E; Thu, 22 Aug 2019 16:26:25 +0000 (UTC) Received: from localhost (unknown [10.40.205.206]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63F595C226; Thu, 22 Aug 2019 16:26:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 22 Aug 2019 18:26:18 +0200 Message-Id: <20190822162618.27670-3-mreitz@redhat.com> In-Reply-To: <20190822162618.27670-1-mreitz@redhat.com> References: <20190822162618.27670-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 22 Aug 2019 16:26:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] iotests: Test reverse sub-cluster qcow2 writes 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 , =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This exercises the regression introduced in commit 50ba5b2d994853b38fed10e0841b119da0f8b8e5. On my machine, it has close to a 50 % false-negative rate, but that should still be sufficient to test the fix. Signed-off-by: Max Reitz Reviewed-by: Anton Nefedov Tested-by: Luk=C3=A1=C5=A1 Doktor --- tests/qemu-iotests/265 | 67 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/265.out | 6 ++++ tests/qemu-iotests/group | 1 + 3 files changed, 74 insertions(+) create mode 100755 tests/qemu-iotests/265 create mode 100644 tests/qemu-iotests/265.out diff --git a/tests/qemu-iotests/265 b/tests/qemu-iotests/265 new file mode 100755 index 0000000000..dce6f77be3 --- /dev/null +++ b/tests/qemu-iotests/265 @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# +# Test reverse-ordered qcow2 writes on a sub-cluster level +# +# Copyright (C) 2019 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 . +# + +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 + +# qcow2-specific test +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +echo '--- Writing to the image ---' + +# Reduce cluster size so we get more and quicker I/O +IMGOPTS=3D'cluster_size=3D4096' _make_test_img 1M +(for ((kb =3D 1024 - 4; kb >=3D 0; kb -=3D 4)); do \ + echo "aio_write -P 42 $((kb + 1))k 2k"; \ + done) \ + | $QEMU_IO "$TEST_IMG" > /dev/null + +echo '--- Verifying its content ---' + +(for ((kb =3D 0; kb < 1024; kb +=3D 4)); do \ + echo "read -P 0 ${kb}k 1k"; \ + echo "read -P 42 $((kb + 1))k 2k"; \ + echo "read -P 0 $((kb + 3))k 1k"; \ + done) \ + | $QEMU_IO "$TEST_IMG" | _filter_qemu_io | grep 'verification' + +# Status of qemu-io +if [ ${PIPESTATUS[1]} =3D 0 ]; then + echo 'Content verified.' +fi + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/265.out b/tests/qemu-iotests/265.out new file mode 100644 index 0000000000..6eac620f25 --- /dev/null +++ b/tests/qemu-iotests/265.out @@ -0,0 +1,6 @@ +QA output created by 265 +--- Writing to the image --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +--- Verifying its content --- +Content verified. +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index d95d556414..0c129c1644 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -274,3 +274,4 @@ 257 rw 258 rw quick 262 rw quick migration +265 rw auto quick --=20 2.21.0