Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7555498ybn; Mon, 30 Sep 2019 16:07:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnjY+M6t93hiQR2NKw9dU9bXeB/R6n2BX14Mt6BR5e69Qf359gPOZKtD2fhx+yXTO80sia X-Received: by 2002:a17:906:4c4c:: with SMTP id d12mr21530729ejw.174.1569884826712; Mon, 30 Sep 2019 16:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569884826; cv=none; d=google.com; s=arc-20160816; b=r9YpQ/nK1Ex5P7SF8wnekn5c43EJyalxm5aOYm4cdM0T5CwlwzgpnSnfAhU8RHe0kr 9ipj5gji7mVpiKt0/9DTnMFGRbheL86qGt159zwzQ5p/JBl+yK/xcn/tHjvYTdU0Pnoc 81eiFi1yaIquu4ulZpxOIOc1ZM7UY2w9bzlLZfWZzDopeuAM2v0tz+M8Azt+RaGNT5eA +xcTZlbEIvCqsccEuQYMwwC/X/hCz+8VqLoggXpZ1CVrX3pFTU8K/qa2nqoJpNiydIno GMQmpPaSCquflsBm2i4oDTY7MMlOZ+of2GnB4/RLZuwnj1XX97PBA+N229/BdsR8xKYr xBjg== 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=LwSaaUd/kUeXILiND58ytLip+C3aQQ7X4RYaZ3Vc3po=; b=mI128mGGA0Ybj1rgj50XOYLNIooIr7TBktoADWYmlnSoFAcMAnWDCVle4+NDzgRTKf xCCbcar+Azo8H/MjN0DF4BTfau5f9Cu4ocXfGW//rTcUqX/+kXKfok2RueoTwsfuvW/c T9zACxLL4Sjf8j7T1WrjXli8hqpvGuUu76DS6eukaqEMqAfTlnEupJuOjqTiP787w2Su WpscpTJryFKKlGuwFZWZcqnSqFzMHApxY4oytzXWwViJk4YwHgxZUYXpqbsvcfof1pp+ EDswKxc6hxzPR975WttbfVjUCP+O0qZXjqh5iPIlSx7XFPp2zX0tVrAnvi5vt/PiuRjG +3mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=XqNbj2zd; 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 l21si7958105edc.112.2019.09.30.16.06.42; Mon, 30 Sep 2019 16:07:06 -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=XqNbj2zd; 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 S1730023AbfI3XEM (ORCPT + 99 others); Mon, 30 Sep 2019 19:04:12 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:47656 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726425AbfI3XEL (ORCPT ); Mon, 30 Sep 2019 19:04:11 -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 x8UI9x5n085059; Mon, 30 Sep 2019 18:25: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=LwSaaUd/kUeXILiND58ytLip+C3aQQ7X4RYaZ3Vc3po=; b=XqNbj2zd+3oHVF+Lpvh/Eifb/Kyeotn/QeNY92U0KAPFg0IYN41nmAc7+vHQv7aRx55V ht/WLv4bpT1ys2Mbufdp5EYDyZAqVS0V1CluDyUB2MG78a1kMVbUTMyzmxrffiAwAgNP EyqUPPaJtWDntYwRFnBcyCOgw9V2lnpnGu6NEv6NR2mPdtF8HH6Xg8QOH9TLGepcmt8T nkCFhUAR9WNgei6b3XBBd4YfE44ahjgXBW8Zab91H/Y8yNB86lkg275tOR2/XLo6Mih0 iUTsPC/OudBfTaP2kw3N6UxXIn/6KWGVNj8ekO+g0EoFDBZN+rpwA/Y+GgiqBQnBjJZL NA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2v9yfq12ye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Sep 2019 18:25:18 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8UIDUrS083260; Mon, 30 Sep 2019 18:25:17 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2vbnqb4bmu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Sep 2019 18:25:17 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x8UIPGJN007705; Mon, 30 Sep 2019 18:25:16 GMT Received: from localhost (/67.161.8.12) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 30 Sep 2019 11:25:15 -0700 Date: Mon, 30 Sep 2019 11:25:15 -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: <20190930182515.GE13108@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=9396 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-1909300165 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9396 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=1015 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-1909300165 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 > > Signed-off-by: Max Reitz Looks ok, will test... Reviewed-by: Darrick J. Wong --D > --- > 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 >