From nobody Sun Apr 28 23:28:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487293137257480.3364872575843; Thu, 16 Feb 2017 16:58:57 -0800 (PST) Received: from localhost ([::1]:51045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWsx-0008KG-Tu for importer@patchew.org; Thu, 16 Feb 2017 19:58:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWm6-00019Q-OP for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceWm5-0007p7-GX for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:50 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33793) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceWm5-0007ny-Af; Thu, 16 Feb 2017 19:51:49 -0500 Received: by mail-wm0-x241.google.com with SMTP id c85so129304wmi.1; Thu, 16 Feb 2017 16:51:49 -0800 (PST) Received: from lean.local (bzq-79-181-80-34.red.bezeqint.net. [79.181.80.34]) by smtp.gmail.com with ESMTPSA id u184sm123712wmb.29.2017.02.16.16.51.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 16:51:47 -0800 (PST) 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; bh=8eyhkju6J6VUQSl1Cf8j+YwFzk44d9oyD/Y18CoV7ZU=; b=rPzGQTbdQ3qMqhRGMD7hqak/+eRbgfMrfSs4Jjghx+RhLPd8o9lqfv2BBimVTV3lOr IJi1D9doSuxT4Q0H9L8UYnzHto/LNSBxGcmBpUFb4ZjLQWiweNplw9Zcu+TxS+3UZcjo 3vyWTsqLQU3nJWvoILITDf2QM61c9ObK+kF9bgp+uxZjd1PLfANdRXoOCgZwIhCsM/V6 5madAu8c98wcbxgkX/1UvbTG37sHzhPmRc9ZJOcE3Hxnb3vs6fjJYEn7HDDCT6JBrErD fjUBqsMcx00R76d/7cXqrjMTILBwdrHVZsomUoa4V//XvaCNnYbbxdcJaKBudXWFHEi2 aE3w== 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; bh=8eyhkju6J6VUQSl1Cf8j+YwFzk44d9oyD/Y18CoV7ZU=; b=pTzfWWFyQPfsvGeDGIDSU1nMvYqhxl/Z4AL7LBP+SNUJPjKZcY/DsYu6xn0mNc91vF jCIJlurs4/VVvwmZ2SotieqFOJ1ofjQ6oqR3ThNsyODds7MNB1aNgPzhv4UL0s7/9dQK IqtW5GFSdsXjnQIXFbR6fOEaXjg3NBuqugOpL2gqnTnPX2SDv8MKi+jwTQgRMpYRo8Bg IKqewLlNJHAsocfXGo2TM6yc8gABtEX8HhvAgF54L+vhUecgpcEElcR0Dr5nTYlP1GVS HffOmSiKmPfn7vlI4s3uHev0CwTYBMtkCOv3tovv1/YDqyuw6I3UBaNHE/2zOqsCyerL qDxg== X-Gm-Message-State: AMke39lZdDgnkks//UFozqkuRHBYjkVhEKRNfbAjV/6esSwiO7BfacYkjpwj7r+ubECBVA== X-Received: by 10.28.211.205 with SMTP id k196mr169455wmg.124.1487292708018; Thu, 16 Feb 2017 16:51:48 -0800 (PST) From: Nir Soffer To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 02:51:25 +0200 Message-Id: <20170217005127.21010-2-nirsof@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170217005127.21010-1-nirsof@gmail.com> References: <20170217005127.21010-1-nirsof@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 1/3] qemu-img: Add tests for raw image preallocation 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, Nir Soffer , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add tests for creating raw image with and without the preallocation option. Signed-off-by: Nir Soffer --- tests/qemu-iotests/175 | 61 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/175.out | 18 ++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 80 insertions(+) create mode 100755 tests/qemu-iotests/175 create mode 100644 tests/qemu-iotests/175.out diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 new file mode 100755 index 0000000..ca56e82 --- /dev/null +++ b/tests/qemu-iotests/175 @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Test creating raw image preallocation mode +# +# Copyright (C) 2017 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 . +# + +# creator +owner=3Dnirsof@gmail.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +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 + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +size=3D1m + +echo +echo "=3D=3D creating image with default preallocation =3D=3D" +_make_test_img $size | _filter_imgfmt +stat -c "size=3D%s, blocks=3D%b" $TEST_IMG + +for mode in off full falloc; do + echo + echo "=3D=3D creating image with preallocation $mode =3D=3D" + IMGOPTS=3Dpreallocation=3D$mode _make_test_img $size | _filter_imgfmt + stat -c "size=3D%s, blocks=3D%b" $TEST_IMG +done + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out new file mode 100644 index 0000000..76c02c6 --- /dev/null +++ b/tests/qemu-iotests/175.out @@ -0,0 +1,18 @@ +QA output created by 175 + +=3D=3D creating image with default preallocation =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +size=3D1048576, blocks=3D0 + +=3D=3D creating image with preallocation off =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Doff +size=3D1048576, blocks=3D0 + +=3D=3D creating image with preallocation full =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfull +size=3D1048576, blocks=3D2048 + +=3D=3D creating image with preallocation falloc =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dfalloc +size=3D1048576, blocks=3D2048 + *** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 985b9a6..1f4bf03 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -167,3 +167,4 @@ 172 auto 173 rw auto 174 auto +175 auto quick --=20 2.9.3 From nobody Sun Apr 28 23:28:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487292799521349.27798850695126; Thu, 16 Feb 2017 16:53:19 -0800 (PST) Received: from localhost ([::1]:51022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWnW-0002rI-98 for importer@patchew.org; Thu, 16 Feb 2017 19:53:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWm7-0001C6-Gq for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceWm6-0007qa-O2 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:51 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceWm6-0007po-I0; Thu, 16 Feb 2017 19:51:50 -0500 Received: by mail-wr0-x241.google.com with SMTP id q39so3775042wrb.2; Thu, 16 Feb 2017 16:51:50 -0800 (PST) Received: from lean.local (bzq-79-181-80-34.red.bezeqint.net. [79.181.80.34]) by smtp.gmail.com with ESMTPSA id u184sm123712wmb.29.2017.02.16.16.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 16:51:48 -0800 (PST) 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; bh=6A2JjvFrrdbYPT2T/is8MFxiKSez/7dvpR7ZphEgdSk=; b=c6UOoiitiq4a01KOSpCyGRhDd0mzN9OF3ymevkdTtVH3rmurkl4uGVxlVQnoiYPpiP fC37Pl1uyxSA6UsDd/v/gh0ah/Qsy2OAEcA2uJbTxeDEow3NxSNgDXWzq2Bw+0Nddv6X r0dBE1qRMQY/eNj16dYjhB0RAmaiVD2R4Io6pWp8786MdIVifTv+08bdyhOxCxnewCH1 VEVkfJLSNTlc27c8mJDD9i7qCBWoCTGsLfzNR+Vkq7VSgcMqBnG79V1zNIoV7eLdOMWZ Zgh+vjZ+OxqtbJJeZXhZT371jbH41bemfRZWvV3BhVRsuABSt6V0y5b5qISpJLOkI2JR 7TTA== 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; bh=6A2JjvFrrdbYPT2T/is8MFxiKSez/7dvpR7ZphEgdSk=; b=blWR+dmU4s3lxBsvmfXuv5QAyM9ZJzEG7XUY+3NKyWRC4YwA0Njhj7bEaujDk3Xceh AOPQg/75x7OS+sG8YtUmxSrDpJceqC55XsATVMSJqdzLIQhLv+zPy2LSw1uwjlYdL1Kc lA+3caqy4ucaHaxhjM+FhINAZ/esflPdjATJmwUhOqI56niNLeK+sWq21QdbVytGqfIy xb0VSR/p5Ta1JzvUg1LQNTtTHlAzWuwztGloBxx9W+MVpjy1V03xsS10mgA897RKG5b9 PFlat13Jf9VcqDv6mSQXw8oySOLoQxw3BewEK4T1pRdauEpdKj9TR89+1591v+w/KxGa uKOQ== X-Gm-Message-State: AMke39mbPy5sX4KRbn56D8e7csOV5q46KtHSfoKfddmURT3OOQpuOD+S25F8IhTxre5bHw== X-Received: by 10.223.177.18 with SMTP id l18mr4466792wra.96.1487292709477; Thu, 16 Feb 2017 16:51:49 -0800 (PST) From: Nir Soffer To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 02:51:26 +0200 Message-Id: <20170217005127.21010-3-nirsof@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170217005127.21010-1-nirsof@gmail.com> References: <20170217005127.21010-1-nirsof@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH 2/3] qemu-img: Truncate before full preallocation 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, Nir Soffer , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In commit 10ddfe7b6044 (qemu-img: Do not truncate before preallocation) we moved truncate to the PREALLOC_MODE_OFF branch to avoid slowdown in posix_fallocate(). However this change is not optimal when using PREALLOC_MODE_FULL, since knowing the final size from the beginning could allow the file system driver to do less allocations and possibly avoid fragmentation of the file. Now we truncate also before doing full preallocation. Signed-off-by: Nir Soffer --- block/file-posix.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 442f080..d24e34b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1604,6 +1604,17 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) #endif case PREALLOC_MODE_FULL: { + /* + * Knowing the final size from the beginning could allow the file + * system driver to do less allocations and possibly avoid + * fragmentation of the file. + */ + if (ftruncate(fd, total_size) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + goto out_close; + } + int64_t num =3D 0, left =3D total_size; buf =3D g_malloc0(65536); =20 @@ -1642,6 +1653,7 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) break; } =20 +out_close: if (qemu_close(fd) !=3D 0 && result =3D=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not close the new file"); --=20 2.9.3 From nobody Sun Apr 28 23:28:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487293027706407.7331262475061; Thu, 16 Feb 2017 16:57:07 -0800 (PST) Received: from localhost ([::1]:51039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWrC-0005VD-ML for importer@patchew.org; Thu, 16 Feb 2017 19:57:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWm9-0001HT-3D for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceWm8-0007sB-4p for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:53 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:35436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceWm7-0007rB-V6; Thu, 16 Feb 2017 19:51:52 -0500 Received: by mail-wr0-x243.google.com with SMTP id q39so3775063wrb.2; Thu, 16 Feb 2017 16:51:51 -0800 (PST) Received: from lean.local (bzq-79-181-80-34.red.bezeqint.net. [79.181.80.34]) by smtp.gmail.com with ESMTPSA id u184sm123712wmb.29.2017.02.16.16.51.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 16:51:50 -0800 (PST) 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; bh=W5kSPSMkBLe3on5gFApAHXIVGAp4L6pHuUT946Qc+0g=; b=CV1FaJRiYp2wWFSouY/l9Cb2g7t/Y+8OVAJgf8aUEL0TwGxLypj6O4RxIuVS8SqRzx 3nYvRXbatjaf58qHa45kT87x4WVl2fVqS/+WPxv1pqzOHfJuigAOUlVMvY8eO1wqXh5v XVOGLz1vXuYbJsP9AmFjAwmPB5Mipu6ih/AT2cX5jB2pWq0jYMUgQK4qj9ionKJazlNa UpKG3grgvShqAEEQ1atvW13SIAfiXRH0Pw4HVfIhN4Vrh1tg9Cd7wuWhyJFlZzwc+YsM UtMtqtnn1XbwhfqO1tyAwbtk9EaHWkToLV5e0LYMPcFSbLKenn/xt0RBvG2pepkRBJg5 kVug== 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; bh=W5kSPSMkBLe3on5gFApAHXIVGAp4L6pHuUT946Qc+0g=; b=g+Fc6r6C4F8NBU2I9iFkn5dfNXqdGfS1JXw2D5SlHrpnhs013AqAJ+6c48g/NRWES7 81GxpMDJU25NA30pmL8Q3viB5gCPfIX00Z9P85VqpSQ7sw9YyPlQEGTYBGJZErPmXsmb vCrf5s1yuRgHziBrXeRKyuAPHKPvrqrg87KJkq4E22f9rnVuOmQ1mJmjtSHZ+ZcI+XKW F6O1qy+JEmNLfTIZHLEZ3Di3SsqYXIRjNekpB6EpAkYLoThX1X1fy5UKShfIM2Uk1fW2 pAXnGQdSrfF9igFDyzWmw70shLfJ/0ImjXyRJIV/AysmUNXw3k3rOFt1TiZpiptITaR1 QylA== X-Gm-Message-State: AMke39lf1lsj7NUqnt7kbxyh+fBeEDuF8EMu1dzx5zrBUK4JPbkc0xUImornGwuRqB42Dg== X-Received: by 10.223.160.132 with SMTP id m4mr4885543wrm.116.1487292710866; Thu, 16 Feb 2017 16:51:50 -0800 (PST) From: Nir Soffer To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 02:51:27 +0200 Message-Id: <20170217005127.21010-4-nirsof@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170217005127.21010-1-nirsof@gmail.com> References: <20170217005127.21010-1-nirsof@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH 3/3] qemu-img: Improve documentation for PREALLOC_MODE_FALLOC 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, Nir Soffer , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that we are truncating the file in both PREALLOC_MODE_FULL and PREALLOC_MODE_OFF, not truncating in PREALLOC_MODE_FALLOC looks odd. Add a comment explaining why we do not truncate in this case. Signed-off-by: Nir Soffer --- block/file-posix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index d24e34b..20a261f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1594,9 +1594,14 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE case PREALLOC_MODE_FALLOC: - /* posix_fallocate() doesn't set errno. */ + /* + * Truncating before posix_fallocate() makes it about twice slower= on + * file systems that do not support fallocate(), trying to check i= f a + * block is allocated before allocating it. + */ result =3D -posix_fallocate(fd, 0, total_size); if (result !=3D 0) { + /* posix_fallocate() doesn't set errno. */ error_setg_errno(errp, -result, "Could not preallocate data for the new file"= ); } --=20 2.9.3