Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752234AbdCaESZ (ORCPT ); Fri, 31 Mar 2017 00:18:25 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:37669 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750763AbdCaESV (ORCPT ); Fri, 31 Mar 2017 00:18:21 -0400 Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=fb.com; Date: Thu, 30 Mar 2017 21:18:00 -0700 From: Calvin Owens To: Brian Foster CC: "Darrick J. Wong" , , , Christoph Hellwig , Dave Chinner , , Subject: [PATCH v3] xfs: Honor FALLOC_FL_KEEP_SIZE when punching ends of files Message-ID: <20170331041800.ugi4wgmbqx44mbwa@Haydn> References: <22a11e65fd5037498a78de61f3ed4dae466ad854.1489791330.git.calvinowens@fb.com> <19504ff40a16efff2e51d85388fce5be578edbc3.1489985397.git.calvinowens@fb.com> <20170321113932.GA58653@bfoster.bfoster> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170306 (1.8.0) X-Originating-IP: [2620:10d:c090:200::c:a991] X-ClientProxiedBy: MWHPR14CA0037.namprd14.prod.outlook.com (10.171.142.151) To CY4PR15MB1221.namprd15.prod.outlook.com (10.172.177.19) X-MS-Office365-Filtering-Correlation-Id: b89ad65e-c21f-44d8-dbfb-08d477ecf05e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:CY4PR15MB1221; X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1221;3:wjv21Ytmk3rSg8WTVLZUIhajRI8PuCkJA1VkrXTJ/a4Va1C5Ff64t4RCDU08h3LX0WrgQF8XTdxsHKHy02zBlw5mTI+QJpfE+9RA6lMvGqsFwBSOcboe8+PQdLHi4Go6gDREZTEpOHDmrSInGEcIKGfJtH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60W/Nj53wEshuSyYJQN+atC3yiVl2KbvkXmiAMllo7a8Nz6d+wskdnRE7gqUkStkgNfALFU18wSzfccY8IIgqN99hdR5wStBxm8VdIdBiJeZtt9AxVezDuDULQzXDJBVoRo+FYP45hR8VJki2rCXhwotsu4lS2FoAr0Lh9gavpzWJxArYXervoyyJNcEMTGKOouFWTiUY8NpcTiaC1+s/4MaWNBbWb8sJBWtQkco+aCUtoJqGFxP/UwWP0DOatTqJYhcsVfsou5ZksSI8dC/ZlXpNoA8jN3g+qlQHZcjgQuBIakk/dDt2lJ2L6Kf7jXsHDhWiS4uKfBOoPZ8BNyI9aaIJNZ7LURkm+JCeLe5X X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006087)(93001087)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123564025)(20161123562025)(20161123555025)(6072148);SRVR:CY4PR15MB1221;BCL:0;PCL:0;RULEID:;SRVR:CY4PR15MB1221; X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1221;4:kdsZzozuo30GkO/Xy6ITaMJ464ZzhPJGLXFM16zDmx0JbZIzqQ4bq3jM2TVP0rW7BWxWrlAWztttJmVJd0UK/+YDZ+u0jf+7YK7mfi9pPtQkW4Nq2GTr8r7PjFdvergk3LUQufbR6KtJKcK11yDdCSOznCZXWgCTLrx4uJijeeUTeWx09kRmcrVoH/9U5L/XaX7wNvu+rePrrIHt4ZM05iZ9ZYC+zALr5RQg14zU79H9TvzcM4+1+kGTbqRFe9HlfkMioxCEgJqgsL6lLt3x1aoytMiWJC7bBT+3Z8956/oFmMlQqNSLEkv2Jv2aOeGmYKJGkeeCbyUs66joMjm3CrRl7/dddQ/6ikUhq3I3D2hhpl8JbTtKh5pMZR0OtufxWiWXkaljAkWLe13aaoMECeBgBggZ0oqpoCBJywOR3qZZBT6bO3AxbqGJjrAJgSkSNoYt7X8DrnH/4KLRcT7AvwP3q1CDrzFeIeKSFIYwA5cT4j8EYWCyhH7Wz4yVhHC23Ae/j3bzkvGSWKokGkDPudnaWXyXXX7EGj7T9sxfq57kNEjNE/Qldgzx3TlkAUFLIJBETRXw9vr3oTpSzx0xgI5FzOXsjmh4QMEIPP5vI1cAOcEsYXkaCCOv/EDk1afZvs5bRWXcLJ0szw6L4/ggAAI0T/mvji+93LKRhuyWoyXlvCm5u3k3tD/31UBo9tLY1wGdsXWTDkMQ4O1S+oIhQllwYai7KK8W3dNRY5qO5u1px6uIaT/CTIhwS/5W+BBnLDfRje1EErV7mzG2LFxF4NxYWNsfDLDSEVCDgZ1Kio8= X-Forefront-PRVS: 02638D901B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39400400002)(39410400002)(39840400002)(39850400002)(39450400003)(43544003)(54906002)(4326008)(7736002)(76176999)(9686003)(55016002)(25786009)(50986999)(6496005)(54356999)(38730400002)(5660300001)(305945005)(110136004)(33716001)(93886004)(33646002)(23676002)(42186005)(50466002)(6116002)(6666003)(2950100002)(1076002)(189998001)(6916009)(86362001)(4001350100001)(2906002)(53936002)(8676002)(83506001)(47776003)(81166006);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR15MB1221;H:Haydn;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjE1TUIxMjIxOzIzOlZ5cFA4OUJrSzlrMlpGRVFUOXgrQUdwS2pE?= =?utf-8?B?UHNrWk00NEovTWRNbURDb0liWnlOTkRjeWhwT3hyWHgwSkZqd1dqcjJVWExy?= =?utf-8?B?V2NuQzdONjNMalUvM3FUQzhLUmpmME1hdE9Gam5kRkYzaHhtTVlxVTRobFYv?= =?utf-8?B?MWh6OUpGVmgxYjBrOEhQczY3WG1EOEhLWTFUWVRvMmt5R2QwS2JXZS9sUkpW?= =?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eEfCnd/uY3v6vEW0ucNNidRi7zky955ZiaAft7vdeipHfnFcg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1221;7:nMSs7gI08rgtXIYoTLGNbT8LSqLxMLeMmL2yapkX4cR07GSFsrO8JTZ4EoQ2+kFPlKc5QLRF46bfIhVwEO/C3GbI30PdU3Y5kuxTG+ObQPKaoaQrjR3WYSRRtpI8yPJdvtw0z6e8m+YoE3DOqP1ZrUqOv1UOXI7kJqyeSXHzGlHHi7H4UwYJ5+FGhk9gOaWrC/4ns4xImVemVzR8Mzk9+MsO5fT9KPCoc4GfRUfmP+ULcFLHV0TLtKBY5SxegVGZQGJzJE72EkGDSnRssJY+DNkbMBB3UOqn0CZrJ2SMK6RIrJtymkrri1pSL1zzRwLJnFUPh6heoWiXhNARfKYdXg==;20:OHiNkTpVGiOvWHBopg2zcZksR8ztVO+2x+Rc3p292HJpWMFwTyRFaZBMH8GsqwZ/FgnNWcMGvz1XcLTJIHpCoY6ywW7R0hAA/BFtuOfJUJYlPE2NyqR6EfJG7FQbRCOwrXFr0dtPtBTylblwI+HDAjKkKKSc3r+nni38dqhQCXY= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2017 04:18:08.8142 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1221 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-03-31_03:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2070 Lines: 53 When punching past EOF on XFS, fallocate(mode=PUNCH_HOLE|KEEP_SIZE) will round the file size up to the nearest multiple of PAGE_SIZE: calvinow@vm-disks/generic-xfs-1 ~$ dd if=/dev/urandom of=test bs=2048 count=1 calvinow@vm-disks/generic-xfs-1 ~$ stat test Size: 2048 Blocks: 8 IO Block: 4096 regular file calvinow@vm-disks/generic-xfs-1 ~$ fallocate -n -l 2048 -o 2048 -p test calvinow@vm-disks/generic-xfs-1 ~$ stat test Size: 4096 Blocks: 8 IO Block: 4096 regular file Commit 3c2bdc912a1cc050 ("xfs: kill xfs_zero_remaining_bytes") replaced xfs_zero_remaining_bytes() with calls to iomap helpers. The new helpers don't enforce that [pos,offset) lies strictly on [0,i_size) when being called from xfs_free_file_space(), so by "leaking" these ranges into xfs_zero_range() we get this buggy behavior. Fix this by reintroducing the checks xfs_zero_remaining_bytes() did against i_size at the bottom of xfs_free_file_space(). Reported-by: Aaron Gao Fixes: 3c2bdc912a1cc050 ("xfs: kill xfs_zero_remaining_bytes") Cc: Christoph Hellwig Cc: Brian Foster Cc: # 4.8+ Signed-off-by: Calvin Owens --- fs/xfs/xfs_bmap_util.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 8b75dce..828532c 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1311,8 +1311,16 @@ xfs_free_file_space( /* * Now that we've unmap all full blocks we'll have to zero out any * partial block at the beginning and/or end. xfs_zero_range is - * smart enough to skip any holes, including those we just created. + * smart enough to skip any holes, including those we just created, + * but we must take care not to zero beyond EOF and enlarge i_size. */ + + if (offset >= XFS_ISIZE(ip)) + return 0; + + if (offset + len > XFS_ISIZE(ip)) + len = XFS_ISIZE(ip) - offset; + return xfs_zero_range(ip, offset, len, NULL); } -- 2.9.3