Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7006739ybi; Thu, 13 Jun 2019 08:03:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4fo7lDcW2INR3gWelPc8oK2GY9cqutDULCK3/nCxeFUqvDi2nDwbsUQhASXLpZzRvdRKD X-Received: by 2002:a17:902:e282:: with SMTP id cf2mr65845458plb.301.1560438226280; Thu, 13 Jun 2019 08:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560438226; cv=none; d=google.com; s=arc-20160816; b=Z5OHYo+fkC84UY0eqtAWdkJIS6NKQyhYRIjICEZv5hYEBcBmi+Yn+mcML1FPP5AM7U HX/E38NuhteN8TT8suS+WSiOel4I0QEVN7eKcLntlXnPPk0C5nFuSyFUMJCdRqHv4Wh2 G4AqbK3Se32eqyu77aPhb24MGe9k+doQYfK7TxlazvA+nPAxPY1KU4iIrwK4EtXjh41a PiS86pyzw10GosBjHX930KjHS6j7pEnCFeKY8e1Dc4H3gm4ijjhIxrQVnk8vdXvBIvVZ myVPLQ6IK4KQbhrGvWuhdPJPHi07N9XhSutxqgXiALJuJV0ozFAt2PZc+DRefgMfmXzW Y5yA== 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=7Gz4cYRh+oElC85Gy1pK6Xy10nwHn3MvUJ0ScJkTm3E=; b=TDN0agLytM38/gcjsC9fNTFX+zKALBVhb5h+DtSMpJukeMKGAx3mL9UI5k/55B2m/9 H3F0cP3P3IWD2KajmAbusFqiBaMIYUbbtqPU1r68OCxqGG09lyBnQH74GK8hhZGC+uty ThAuP0JsRogCZ2Z5GUGpIe9vcyubR18IhwkObhNBSzEoSv9qk0L0WLIso4HJOPeceXuD FU67FnADR2mqp5vzVSR+c3EsNttLUFa0xyXE5+0wFk6OwEIRZWcJHNb0zoc/Y1/eLdfm nwGLBSgIMjyzre3N7Fq8jHdXR/mSIFi1fkF26uAzFVrv3FDTkPdKW1z+DETXRTSBXTbe CaHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="uI/WQ5SJ"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m25si31605pgv.481.2019.06.13.08.03.30; Thu, 13 Jun 2019 08:03:46 -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=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="uI/WQ5SJ"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733152AbfFMPCc (ORCPT + 99 others); Thu, 13 Jun 2019 11:02:32 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:34464 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732509AbfFMO0B (ORCPT ); Thu, 13 Jun 2019 10:26:01 -0400 Received: by mail-qt1-f195.google.com with SMTP id m29so22772098qtu.1 for ; Thu, 13 Jun 2019 07:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7Gz4cYRh+oElC85Gy1pK6Xy10nwHn3MvUJ0ScJkTm3E=; b=uI/WQ5SJ/Qt2yWiJ1l/NoXQydtuj3RBnifEE0KmNR+6FVkvydHwwsCA93oVRfFgx+5 BbP4HXJl+lJPEFu0NtF2YEmfE80+FvyYM15T/vSlwPRXeJ6pt7imuegIW7KylC65MCvg HqplX/eVXsXZ5Oe3RwAMtqeGscFQsCJhbYU5IwTd7TsNM2qDuTmvIa0NUaGcN/Goudsi pjkI7EP4IVbghzl/wKxWw0i4piIgyDi+TSc2g1oPZ/yWjj8IEXIp70nC/K98Cbo2Ncvu r0cfi8q/MlVGtDGtLGM1t7f9pgXz18KeabwhOelrkXfpR/joO78cnX9fH7oHr+JZlnuW HPCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=7Gz4cYRh+oElC85Gy1pK6Xy10nwHn3MvUJ0ScJkTm3E=; b=PecNSK04cbL0DL0uhby3dWif+NuDOZ132sk1yNwX6kmzCMeXxcftwuduifoqw1HbRN 9WgEJXm0g+3LhsRIqHFytJ6LAmXYmkyDt0zehWjr4izl7YKj+7/D2R3AUksFS7kMZByx aElXO/PHFOlI+ill5zop2tdhxkuoFJDR8RI1QXA/WsMfLQ9tGUO0gI1SR3aYPwxgGR8N 7vzRzHF3a7L4qQynTvD+jyc+hx2ZRNf8Pru4Se2rKhQAxGsnwapEbXgQpXCId55DOA8B jEwvY+NiAnYccvd5Tqp6oBFOCXVnS7/JPasFcKRSM6pd6cagatOGlGQxjyffjCVVOQ7v /8Yw== X-Gm-Message-State: APjAAAXnc1XstrpotOdYupuaXqq/JS/Xg8Rz1VMQGmK76hbMdsM/SpiZ XtBu7QYOl+5cm6bHk5mGIYLvgaRmYL3sw6XG X-Received: by 2002:ac8:1b64:: with SMTP id p33mr77811221qtk.62.1560435960588; Thu, 13 Jun 2019 07:26:00 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::9d6b]) by smtp.gmail.com with ESMTPSA id q37sm1950915qtj.94.2019.06.13.07.25.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 07:25:59 -0700 (PDT) Date: Thu, 13 Jun 2019 10:25:58 -0400 From: Josef Bacik To: Naohiro Aota Cc: linux-btrfs@vger.kernel.org, David Sterba , Chris Mason , Josef Bacik , Qu Wenruo , Nikolay Borisov , linux-kernel@vger.kernel.org, Hannes Reinecke , linux-fsdevel@vger.kernel.org, Damien Le Moal , Matias =?utf-8?B?QmrDuHJsaW5n?= , Johannes Thumshirn , Bart Van Assche Subject: Re: [PATCH 16/19] btrfs: wait existing extents before truncating Message-ID: <20190613142557.sexckoyaylbspran@MacBook-Pro-91.local> References: <20190607131025.31996-1-naohiro.aota@wdc.com> <20190607131025.31996-17-naohiro.aota@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190607131025.31996-17-naohiro.aota@wdc.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 07, 2019 at 10:10:22PM +0900, Naohiro Aota wrote: > When truncating a file, file buffers which have already been allocated but > not yet written may be truncated. Truncating these buffers could cause > breakage of a sequential write pattern in a block group if the truncated > blocks are for example followed by blocks allocated to another file. To > avoid this problem, always wait for write out of all unwritten buffers > before proceeding with the truncate execution. > > Signed-off-by: Naohiro Aota > --- > fs/btrfs/inode.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index 89542c19d09e..4e8c7921462f 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -5137,6 +5137,17 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) > btrfs_end_write_no_snapshotting(root); > btrfs_end_transaction(trans); > } else { > + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); > + > + if (btrfs_fs_incompat(fs_info, HMZONED)) { > + u64 sectormask = fs_info->sectorsize - 1; > + > + ret = btrfs_wait_ordered_range(inode, > + newsize & (~sectormask), > + (u64)-1); Use ALIGN(). Thanks, Josef