Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1681310ybz; Thu, 16 Apr 2020 13:34:44 -0700 (PDT) X-Google-Smtp-Source: APiQypKtrc4OxvdW/G/jzo5TRLa0SNfPpDCxhn/nBWvOAUcue77U8kbUsq81OxQ+WHWv9tGWVJ5B X-Received: by 2002:a17:906:5608:: with SMTP id f8mr11754113ejq.190.1587069284605; Thu, 16 Apr 2020 13:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069284; cv=none; d=google.com; s=arc-20160816; b=tv7sQ5G1m3HrjXbzEFUMWWK5ipuj+D/Hko/1ix0RhPhjUfUrfra/se+7RxoVJovO66 I4zVfevkKGRn49pCNrk/Oea6YsTFeAGJGTgXxe374QBobkO6ZTkU9wgEs7uIaQIxAtzb ZJc28qw4WO01SG2q4/lR+81Tx+52nxww5sPbcIoZgNIcm7f0zDvjwdAuIfaxsPHk0oGf S/I80jfwBlZImhgzVjPnbFBdzrP1gWyZIHeIfgQFawoiKQwCsVm9cMvczrohRVvjare/ NiOA3YQutFvHAzGhdvEwfsPjNZ3C2Bw6ba9A0lElyAEX4hx8rcdZkjIZSK7CHip8EVex UFYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4SxbyPoSa7U9lfDWEM42JCOC7bCcTxbT4OOvp9W6jtI=; b=xl3MIyGgADESP884MZesJNgqEVC/soFpIgaQVKHCnRYpUtzvDj1y9MWU6q97DxvNYQ GtOVgYFqLNEiMWgatE+DM3zzNZYBBbFI4DxsUIcPH3Qat59a6w2O6DuJpErcWo5WOY1A Jc7TGLMuEDc+JX7k8KYAxt3X5FKBsZrGZo3TBqh/Iada57COb/xXyR0xGsHjWKU70nOB ORgfnpxpB7dUBDy5iwR6NGRsblfnGjhg5RXAQMqHF4/H6g51VYH2euDCSjTwqhqcHC7B hdtFn+XvzL1Q2Lkcd3m8KboaSiG5qajeo9TmvB3vUfYU7UczPzyfFkHgmY5A595b8Qk3 6U+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FIn3utZs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si14710020edq.249.2020.04.16.13.34.21; Thu, 16 Apr 2020 13:34:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FIn3utZs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442409AbgDPPTB (ORCPT + 99 others); Thu, 16 Apr 2020 11:19:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:34134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392304AbgDPNsG (ORCPT ); Thu, 16 Apr 2020 09:48:06 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 417E2208E4; Thu, 16 Apr 2020 13:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587044884; bh=0CSh/3iuY/hLOBpsWWHw2RMNg5o9HoNcm5Ux17DNj/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FIn3utZs4QmF1v7FLH6Iv6X5UQf7TZvOpGAYsfNGeXC72fdRRIeQ7Yg9vbPfFpSLR LP2S5zkjRt2x4ooWnj3FekNbuBpJeWZpQSKvc2oaB/J+5sJjSmxw6g33oUcIfU3xA6 FCcBT42juApaTTtTt+UOfDWMshtCKvNdyJ8hbjSY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Filipe Manana , David Sterba Subject: [PATCH 5.4 142/232] btrfs: fix missing file extent item for hole after ranged fsync Date: Thu, 16 Apr 2020 15:23:56 +0200 Message-Id: <20200416131332.736666825@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana commit 95418ed1d10774cd9a49af6f39e216c1256f1eeb upstream. When doing a fast fsync for a range that starts at an offset greater than zero, we can end up with a log that when replayed causes the respective inode miss a file extent item representing a hole if we are not using the NO_HOLES feature. This is because for fast fsyncs we don't log any extents that cover a range different from the one requested in the fsync. Example scenario to trigger it: $ mkfs.btrfs -O ^no-holes -f /dev/sdd $ mount /dev/sdd /mnt # Create a file with a single 256K and fsync it to clear to full sync # bit in the inode - we want the msync below to trigger a fast fsync. $ xfs_io -f -c "pwrite -S 0xab 0 256K" -c "fsync" /mnt/foo # Force a transaction commit and wipe out the log tree. $ sync # Dirty 768K of data, increasing the file size to 1Mb, and flush only # the range from 256K to 512K without updating the log tree # (sync_file_range() does not trigger fsync, it only starts writeback # and waits for it to finish). $ xfs_io -c "pwrite -S 0xcd 256K 768K" /mnt/foo $ xfs_io -c "sync_range -abw 256K 256K" /mnt/foo # Now dirty the range from 768K to 1M again and sync that range. $ xfs_io -c "mmap -w 768K 256K" \ -c "mwrite -S 0xef 768K 256K" \ -c "msync -s 768K 256K" \ -c "munmap" \ /mnt/foo # Mount to replay the log. $ mount /dev/sdd /mnt $ umount /mnt $ btrfs check /dev/sdd Opening filesystem to check... Checking filesystem on /dev/sdd UUID: 482fb574-b288-478e-a190-a9c44a78fca6 [1/7] checking root items [2/7] checking extents [3/7] checking free space cache [4/7] checking fs roots root 5 inode 257 errors 100, file extent discount Found file extent holes: start: 262144, len: 524288 ERROR: errors found in fs roots found 720896 bytes used, error(s) found total csum bytes: 512 total tree bytes: 131072 total fs tree bytes: 32768 total extent tree bytes: 16384 btree space waste bytes: 123514 file data blocks allocated: 589824 referenced 589824 Fix this issue by setting the range to full (0 to LLONG_MAX) when the NO_HOLES feature is not enabled. This results in extra work being done but it gives the guarantee we don't end up with missing holes after replaying the log. CC: stable@vger.kernel.org # 4.19+ Reviewed-by: Josef Bacik Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2074,6 +2074,16 @@ int btrfs_sync_file(struct file *file, l btrfs_init_log_ctx(&ctx, inode); /* + * Set the range to full if the NO_HOLES feature is not enabled. + * This is to avoid missing file extent items representing holes after + * replaying the log. + */ + if (!btrfs_fs_incompat(fs_info, NO_HOLES)) { + start = 0; + end = LLONG_MAX; + } + + /* * We write the dirty pages in the range and wait until they complete * out of the ->i_mutex. If so, we can flush the dirty pages by * multi-task, and make the performance up. See