Return-Path: Received: from mail-eopbgr700130.outbound.protection.outlook.com ([40.107.70.130]:45344 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726235AbeH3WUE (ORCPT ); Thu, 30 Aug 2018 18:20:04 -0400 From: Sasha Levin To: "stable@vger.kernel.org" CC: Misono Tomohiro , David Sterba , Sasha Levin Subject: [PATCH AUTOSEL 4.4 28/30] btrfs: replace: Reset on-disk dev stats value after replace Date: Thu, 30 Aug 2018 18:16:38 +0000 Message-ID: <20180830181533.36683-28-alexander.levin@microsoft.com> References: <20180830181533.36683-1-alexander.levin@microsoft.com> In-Reply-To: <20180830181533.36683-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Misono Tomohiro [ Upstream commit 1e7e1f9e3aba00c9b9c323bfeeddafe69ff21ff6 ] on-disk devs stats value is updated in btrfs_run_dev_stats(), which is called during commit transaction, if device->dev_stats_ccnt is not zero. Since current replace operation does not touch dev_stats_ccnt, on-disk dev stats value is not updated. Therefore "btrfs device stats" may return old device's value after umount/mount (Example: See "btrfs ins dump-t -t DEV $DEV" after btrfs/100 finish). Fix this by just incrementing dev_stats_ccnt in btrfs_dev_replace_finishing() when replace is succeeded and this will update the values. Signed-off-by: Misono Tomohiro Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/dev-replace.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 1e668fb7dd4c..176a27bc63aa 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -573,6 +573,12 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs= _info *fs_info, =20 btrfs_rm_dev_replace_unblocked(fs_info); =20 + /* + * Increment dev_stats_ccnt so that btrfs_run_dev_stats() will + * update on-disk dev stats value during commit transaction + */ + atomic_inc(&tgt_device->dev_stats_ccnt); + /* * this is again a consistent state where no dev_replace procedure * is running, the target device is part of the filesystem, the --=20 2.17.1