From: Qu Wenruo <wqu@suse.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 0/4] btrfs: DEV_STATS item related minor fixes
Date: Tue, 14 Apr 2026 07:28:16 +0930 [thread overview]
Message-ID: <e79dfddc-fcff-4e16-8964-9fcf777dd49d@suse.com> (raw)
In-Reply-To: <20260413185907.GG12792@twin.jikos.cz>
在 2026/4/14 04:29, David Sterba 写道:
> On Tue, Apr 07, 2026 at 07:03:57PM +0930, Qu Wenruo wrote:
>> [BACKGROUND]
>> DEV_STATS (objectid, not type) items are storing the error counts for
>> each device. It's updated every time an error is hit, including
>> the following types:
>>
>> - READ errors
>> - WRITE errors
>> - FLUSH errors
>> Above alls are all errors directly returned from the device.
>>
>> - CORRUPTION errors
>> Aka, checksum mismatch.
>>
>> - GENERATION errors
>> Metadata generation mismatch.
>>
>> [MINOR BUGS]
>> Recently when debugging an error reported about rejected dev-replace,
>> the device tree dump includes a DEV_STATS item for devid 0.
>>
>> I'm wondering if that DEV_STATS item will ever be deleted, but
>> unfortunately it will never be deleted.
>>
>> Normally it's not a big deal, as the DEV_STATS are normally all zeros.
>>
>> But if it's not, and a new dev-replace is started and interrupted, at
>> the next mount the replace target device will suddenly inherit all the
>> error records, giving end users false alerts about a completely good
>> device.
>>
>> [FIX]
>> The first 2 are manually removing the DEV_STATS items when dev-replace
>> and dev-removal finishes.
>
> The device stat item is expected by btrfs-progs even if it's just zeros,
> otherwise the 'btrfs device stats' prints just 'no stats found'.
That's not true.
Firstly when btrfs is created, there is no device stats at all, it's at
the first RW mount we create the dev status item when initializing the
dev status.
Secondly, all device adding ioctl has the proper update to force a dev
status update, thus they will properly have one no matter what.
And that's what the older kernel missing.
With those features guarding the dev status, it's pretty safe to remove
the old dev status.
> This
> has a high potential to break any monitoring tools or scripts. So please
> don't delete the item, and create it empty in case it does not exist.
Please give me an example where it doesn't work.
The only situation where no dev stats item can be found is for the
unpatched kernels with offline dev stats query.
After a new device is added, no new dev stats item is added (requires an
error to create), thus it requires a new RW mount to create them.
But before that, there is no such stats item, and offline dev stats call
will not find the item.
And device removal/replace won't change the situation.
For kernel GET_DEV_STATS ioctl it's not a problem at all, because kernel
always grab the numbers from the in-memory structure which always exists.
Thanks,
Qu
>
> For the wrong stats on the replaced device the stats should be zero from
> the beginning of the operation.
next prev parent reply other threads:[~2026-04-13 21:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 9:33 [PATCH 0/4] btrfs: DEV_STATS item related minor fixes Qu Wenruo
2026-04-07 9:33 ` [PATCH 1/4] btrfs: remove the dev stats item for replace target device Qu Wenruo
2026-04-07 9:33 ` [PATCH 2/4] btrfs: remove the dev stats item when removing a device Qu Wenruo
2026-04-07 9:34 ` [PATCH 3/4] btrfs: always update/create the dev stats item when adding a new device Qu Wenruo
2026-04-07 9:34 ` [PATCH 4/4] btrfs: avoid unnecessary dev stats updates Qu Wenruo
2026-04-13 18:59 ` [PATCH 0/4] btrfs: DEV_STATS item related minor fixes David Sterba
2026-04-13 21:58 ` Qu Wenruo [this message]
2026-04-13 22:03 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e79dfddc-fcff-4e16-8964-9fcf777dd49d@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox