Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp2145168ybn; Thu, 26 Sep 2019 07:39:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxovU5+Btoei3GKYtLNTPEVBEKr8WhOP6RSSRSZ7VEIWLk/V8GDthvulS5pC8UQQnIuk/IY X-Received: by 2002:a17:906:1310:: with SMTP id w16mr3379801ejb.73.1569508798139; Thu, 26 Sep 2019 07:39:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569508798; cv=none; d=google.com; s=arc-20160816; b=lHgPUanho4Lr1AfnkHa41WF6nY45DWC3hg5lcRY3BHVq4oBkB2BYxZvxLKGDWBNnZN AjlyTONjsUXepNAFU+M3YP9qzZkXL0K+xo784+3tYZ4RurHmI77DI207svNOwui5xdCa V20fli1pzKWfI4zQoxXQWHZ/ckABlvmd8jlKmT29fvcDWLH9ub6QyTWp+llB4YS0scFd yh6e7zRVdym3v2oaXzRNtluYWEwC1IwLiclW9IdLzw/7akJ2qZVOwjKEIi+hEKnIbp4d nfPg95RJhVIlBd7S482CtPpAbzi2POCmdHR8NdBL5aKriWfMm5xNKpKlcWgt2FnzQqrq 1ccw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Tmwprk0lmnBQUvHH6rcVvYGRhpZqa3f3F/w8fDa9Ts8=; b=gdW6oZ3Kd+ABF6cwoh1A1f/G3AVivSOyDC2zHSV7DMWa5rWT0OtJYVFWtp0QJ7JdDo /mC3U//FtvvtyztzBMlvMd+HJZACmaEAF4TCc+Z7k/QOfVBDkurw3O2xwSJlVM/lmh7k G4+s+xTZydxAfCsOy1zAv79tMqLOaNrsAtKECeH1qNY1fZErzre+VwJ+Od1hzfNk2fRu lKkA6HWz59avSj3soLvTtU+X/izcVZAiNgB2FARG3sRQdt3/gdvuc93lr/bfnWxxZEBT nYu8b1Wj6rRvyHb246e6v1SEfYQrRPcSxxDgRZuuKnvHEd3ur7UxJHvJkzhcrRcG+wJx VKiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=lidc6vmd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6si1470960eda.336.2019.09.26.07.39.33; Thu, 26 Sep 2019 07:39:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=lidc6vmd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727176AbfIZOhj (ORCPT + 99 others); Thu, 26 Sep 2019 10:37:39 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56366 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbfIZOhj (ORCPT ); Thu, 26 Sep 2019 10:37:39 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8QEY801046697; Thu, 26 Sep 2019 14:37:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2019-08-05; bh=Tmwprk0lmnBQUvHH6rcVvYGRhpZqa3f3F/w8fDa9Ts8=; b=lidc6vmdhRiA2mGaRp9GVXrqJAFJszgZoL+ZlLLe1Hxo6rELzrQ0HyQ53Duc6rXuLApd epfILGWVDMuZNrHPGaTmVzFkvWHNMlwJtxnU+HBjNOyzFGF8wYRZ61RTgEtwQCPK+WWJ gkIhY401XKGCPIe32P20+V1ZAoIzgVoNjDxRbfgJ5cIl7RCTBPki+sUebhL5tHhq+ciB 4qmBiHh9jDgFz7Qp7oYTWKwHFdIQyOFCQd9oDM6HEbjEBYmyYs4584V89hMK6Gee0Xn1 owuMeiC+18w0lZSjMvVci4i0YpIjkSE8QbSKt3lQxaKNpt8pEohYNXxcTdDWQwNDsV4Q 6g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2v5btqc8m7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2019 14:37:17 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8QETAA8157716; Thu, 26 Sep 2019 14:37:17 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2v8rvtcjys-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2019 14:37:16 +0000 Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8QEbGIm006943; Thu, 26 Sep 2019 14:37:16 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 26 Sep 2019 07:37:15 -0700 Date: Thu, 26 Sep 2019 07:37:14 -0700 From: "Darrick J. Wong" To: Max Reitz Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Foster Subject: Re: [PATCH] xfs: Fix tail rounding in xfs_alloc_file_space() Message-ID: <20190926143704.GA9916@magnolia> References: <20190926142238.26973-1-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190926142238.26973-1-mreitz@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9391 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909260134 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9391 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909260135 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 26, 2019 at 04:22:38PM +0200, Max Reitz wrote: > To ensure that all blocks touched by the range [offset, offset + count) > are allocated, we need to calculate the block count from the difference > of the range end (rounded up) and the range start (rounded down). > > Before this patch, we just round up the byte count, which may lead to > unaligned ranges not being fully allocated: > > $ touch test_file > $ block_size=$(stat -fc '%S' test_file) > $ fallocate -o $((block_size / 2)) -l $block_size test_file > $ xfs_bmap test_file > test_file: > 0: [0..7]: 1396264..1396271 > 1: [8..15]: hole > > There should not be a hole there. Instead, the first two blocks should > be fully allocated. > > With this patch applied, the result is something like this: > > $ touch test_file > $ block_size=$(stat -fc '%S' test_file) > $ fallocate -o $((block_size / 2)) -l $block_size test_file > $ xfs_bmap test_file > test_file: > 0: [0..15]: 11024..11039 Code looks ok; by any chance do you have an xfstest we could add to the regresion test suite? --D > Signed-off-by: Max Reitz > --- > fs/xfs/xfs_bmap_util.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c > index 0910cb75b65d..4f443703065e 100644 > --- a/fs/xfs/xfs_bmap_util.c > +++ b/fs/xfs/xfs_bmap_util.c > @@ -864,6 +864,7 @@ xfs_alloc_file_space( > xfs_filblks_t allocatesize_fsb; > xfs_extlen_t extsz, temp; > xfs_fileoff_t startoffset_fsb; > + xfs_fileoff_t endoffset_fsb; > int nimaps; > int quota_flag; > int rt; > @@ -891,7 +892,8 @@ xfs_alloc_file_space( > imapp = &imaps[0]; > nimaps = 1; > startoffset_fsb = XFS_B_TO_FSBT(mp, offset); > - allocatesize_fsb = XFS_B_TO_FSB(mp, count); > + endoffset_fsb = XFS_B_TO_FSB(mp, offset + count); > + allocatesize_fsb = endoffset_fsb - startoffset_fsb; > > /* > * Allocate file space until done or until there is an error > -- > 2.23.0 >