From nobody Sun May 5 05:35:24 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=1557522902; cv=none; d=zoho.com; s=zohoarc; b=bzKQFuBCJOlsSxzB4/HIqJsauFgjjo9j9nrEacmr0Yo3xP2qfAbwqV3Lis1hihMxPKGBgVXAMgPfP7T/0h19b/w5ZehTYn7CshVX1Oqy8iT4h8Uw84Z6ySlGgRbxmEmY5u8Lgz4LXVKwWYurpouSxyKKALNTk9bWUS3+67UB4Qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557522902; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=gJBw7WYVeVEqdSKKu/XzUDJgou67Rni2gnK1CH21maE=; b=iInUI9gtBEGhjuD9kIc6LHfWkI6TLJia5GAQY8H+nVcfH0FNXY7u673qVZgM6Qb7b9FhRP2ti9/k2TPTe2D+KH4c+raRypgbYyvv7HqCMzc8Q4udVLwoZ5EnVIDHu1UuWqdLeoiu6swaDkhofxpK46lwiZItkuG+amrGz1KOlbU= 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 15575229021433.6463859061815356; Fri, 10 May 2019 14:15:02 -0700 (PDT) Received: from localhost ([127.0.0.1]:50085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPCr5-0005RE-7M for importer@patchew.org; Fri, 10 May 2019 17:14:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPCp0-0004FK-0U for qemu-devel@nongnu.org; Fri, 10 May 2019 17:12:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hPCoz-0002p4-5S for qemu-devel@nongnu.org; Fri, 10 May 2019 17:12:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hPCox-0002nh-5L; Fri, 10 May 2019 17:12:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B17A3082206; Fri, 10 May 2019 21:12:46 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13ACE1A267; Fri, 10 May 2019 21:12:45 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 10 May 2019 23:12:44 +0200 Message-Id: <20190510211244.26461-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 10 May 2019 21:12:46 +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] block/file-posix: Truncate in xfs_write_zeroes() 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: Kevin Wolf , 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" XFS_IOC_ZERO_RANGE does not increase the file length: $ touch foo $ xfs_io -c 'zero 0 65536' foo $ stat -c "size=3D%s, blocks=3D%b" foo size=3D0, blocks=3D128 We do want writes beyond the EOF to automatically increase the file length, however. This is evidenced by the fact that iotest 061 is broken on XFS since qcow2's check implementation checks for blocks beyond the EOF. Reported-by: Kevin Wolf Signed-off-by: Max Reitz --- block/file-posix.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 1cf4ee49eb..e09e15bbf8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1444,9 +1444,22 @@ out: #ifdef CONFIG_XFS static int xfs_write_zeroes(BDRVRawState *s, int64_t offset, uint64_t byte= s) { + int64_t len; struct xfs_flock64 fl; int err; =20 + len =3D lseek(s->fd, 0, SEEK_END); + if (len < 0) { + return -errno; + } + + if (offset + bytes > len) { + /* XFS_IOC_ZERO_RANGE does not increase the file length */ + if (ftruncate(s->fd, offset + bytes) < 0) { + return -errno; + } + } + memset(&fl, 0, sizeof(fl)); fl.l_whence =3D SEEK_SET; fl.l_start =3D offset; --=20 2.21.0