From: Torstein Eide <torsteine@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Torstein Eide <torsteine@gmail.com>
Subject: [PATCH 4/5] btrfs: hook scrub session tracking into btrfs_scrub_dev()
Date: Sun, 19 Apr 2026 16:26:16 +0200 [thread overview]
Message-ID: <20260419142618.3147763-5-torsteine+linux@gmail.com> (raw)
In-Reply-To: <20260419142618.3147763-1-torsteine+linux@gmail.com>
From: Torstein Eide <torsteine@gmail.com>
At the start of a scrub (excluding device replace runs):
- zero all per-device scrub_session_values[] counters
- set scrub_session_last_physical to the start offset
- record scrub_session_t_start (wall-clock seconds)
- set scrub_session_status to BTRFS_SCRUB_STATUS_RUNNING
At the end of a scrub, call btrfs_update_scrub_stats() which copies
the final btrfs_scrub_progress counters into the session and lifetime
arrays, stamps t_end, and sets the status to FINISHED or CANCELED
depending on the return value.
Device replace runs are excluded because their progress is tracked
separately and their statistics should not pollute the device's own
scrub history.
Signed-off-by: Torstein Eide <torsteine@gmail.com>
Assisted-by: Claude:claude-sonnet-4-6
---
fs/btrfs/scrub.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 1ac609239cbe3..a3bf3276f5f44 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -6,6 +6,7 @@
#include <linux/blkdev.h>
#include <linux/ratelimit.h>
#include <linux/sched/mm.h>
+#include <linux/timekeeping.h>
#include "ctree.h"
#include "discard.h"
#include "volumes.h"
@@ -3152,6 +3153,18 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
dev->scrub_ctx = sctx;
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ if (!is_dev_replace) {
+ int i;
+
+ /* Reset session counters for this new scrub run */
+ for (i = 0; i < BTRFS_SCRUB_STAT_VALUES_MAX; i++)
+ atomic64_set(&dev->scrub_session_values[i], 0);
+ dev->scrub_session_last_physical = start;
+ dev->scrub_session_t_start = ktime_get_real_seconds();
+ dev->scrub_session_t_end = 0;
+ atomic_set(&dev->scrub_session_status, BTRFS_SCRUB_STATUS_RUNNING);
+ }
+
/*
* checking @scrub_pause_req here, we can avoid
* race between committing transaction and scrubbing.
@@ -3207,6 +3220,9 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
if (progress)
memcpy(progress, &sctx->stat, sizeof(*progress));
+ if (!is_dev_replace)
+ btrfs_update_scrub_stats(dev, &sctx->stat, ret);
+
if (!is_dev_replace)
btrfs_info(fs_info, "scrub: %s on devid %llu with status: %d",
ret ? "not finished" : "finished", devid, ret);
--
2.48.1
next prev parent reply other threads:[~2026-04-19 14:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 14:26 [PATCH 0/5] btrfs: add persistent scrub lifetime and session counters Torstein Eide
2026-04-19 14:26 ` [PATCH 1/5] btrfs: uapi: introduce on-disk scrub stats item Torstein Eide
2026-04-19 14:26 ` [PATCH 2/5] btrfs: add in-memory scrub lifetime and session fields Torstein Eide
2026-04-19 14:26 ` [PATCH 3/5] btrfs: persist scrub lifetime stats to the device tree Torstein Eide
2026-04-19 14:26 ` Torstein Eide [this message]
2026-04-19 14:26 ` [PATCH 5/5] btrfs: expose scrub lifetime and session counters via sysfs Torstein Eide
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=20260419142618.3147763-5-torsteine+linux@gmail.com \
--to=torsteine@gmail.com \
--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