Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Torstein Eide <torsteine@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Torstein Eide <torsteine@gmail.com>
Subject: [PATCH 1/5] btrfs: uapi: introduce on-disk scrub stats item
Date: Sun, 19 Apr 2026 16:26:13 +0200	[thread overview]
Message-ID: <20260419142618.3147763-2-torsteine+linux@gmail.com> (raw)
In-Reply-To: <20260419142618.3147763-1-torsteine+linux@gmail.com>

From: Torstein Eide <torsteine@gmail.com>

Add a new persistent item type for per-device scrub lifetime counters:

  Key: (BTRFS_SCRUB_STATS_OBJECTID, BTRFS_PERSISTENT_ITEM_KEY, devid)

The item payload is struct btrfs_scrub_stats_item, an array of __le64
values indexed by BTRFS_SCRUB_STAT_* constants (data/tree extents and
bytes scrubbed, read/checksum/verify/malloc errors, etc.).

The array is designed to grow at the end; existing index values are
fixed and must not be renumbered.  New entries should be appended and
the item_size check in the reader handles shorter on-disk items from
older kernels gracefully.

Signed-off-by: Torstein Eide <torsteine@gmail.com>
Assisted-by: Claude:claude-sonnet-4-6
---
 include/uapi/linux/btrfs_tree.h | 34 +++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index cc3b9f7dccafa..7eb775b6b6253 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -82,6 +82,9 @@
 /* device stats in the device tree */
 #define BTRFS_DEV_STATS_OBJECTID 0ULL
 
+/* per-device scrub lifetime stats in the device tree */
+#define BTRFS_SCRUB_STATS_OBJECTID 1ULL
+
 /* for storing balance parameters in the root tree */
 #define BTRFS_BALANCE_OBJECTID -4ULL
 
@@ -1139,6 +1142,37 @@ struct btrfs_dev_stats_item {
 	__le64 values[BTRFS_DEV_STAT_VALUES_MAX];
 } __attribute__ ((__packed__));
 
+/*
+ * Scrub lifetime error counters, stored per device in the device tree.
+ * Key: (BTRFS_SCRUB_STATS_OBJECTID, BTRFS_PERSISTENT_ITEM_KEY, devid)
+ *
+ * Index values are defined by enum btrfs_scrub_stat_index in btrfs_tree.h
+ * (kernel-internal, not exposed via ioctl).
+ */
+#define BTRFS_SCRUB_STAT_DATA_EXTENTS_SCRUBBED		0
+#define BTRFS_SCRUB_STAT_TREE_EXTENTS_SCRUBBED		1
+#define BTRFS_SCRUB_STAT_DATA_BYTES_SCRUBBED		2
+#define BTRFS_SCRUB_STAT_TREE_BYTES_SCRUBBED		3
+#define BTRFS_SCRUB_STAT_READ_ERRORS			4
+#define BTRFS_SCRUB_STAT_CSUM_ERRORS			5
+#define BTRFS_SCRUB_STAT_VERIFY_ERRORS			6
+#define BTRFS_SCRUB_STAT_NO_CSUM			7
+#define BTRFS_SCRUB_STAT_CSUM_DISCARDS			8
+#define BTRFS_SCRUB_STAT_SUPER_ERRORS			9
+#define BTRFS_SCRUB_STAT_MALLOC_ERRORS			10
+#define BTRFS_SCRUB_STAT_UNCORRECTABLE_ERRORS		11
+#define BTRFS_SCRUB_STAT_CORRECTED_ERRORS		12
+#define BTRFS_SCRUB_STAT_UNVERIFIED_ERRORS		13
+#define BTRFS_SCRUB_STAT_VALUES_MAX			14
+
+struct btrfs_scrub_stats_item {
+	/*
+	 * Grow at the end for future enhancements; keep existing values
+	 * unchanged.  Index values defined by BTRFS_SCRUB_STAT_* above.
+	 */
+	__le64 values[BTRFS_SCRUB_STAT_VALUES_MAX];
+} __attribute__ ((__packed__));
+
 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS	0
 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID	1
 
-- 
2.48.1


  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 ` Torstein Eide [this message]
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 ` [PATCH 4/5] btrfs: hook scrub session tracking into btrfs_scrub_dev() Torstein Eide
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-2-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