]> git.hungrycats.org Git - bees/commitdiff
crucible: report when COMMIT_ROOT support has been confirmed
authorZygo Blaxell <bees@furryterror.org>
Thu, 24 Sep 2026 02:11:14 +0000 (22:11 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
commit_root_supported() stays true while support is unknown, which is
what callers need when deciding whether to keep setting the flag.  A
caller that wants to relax something only once the kernel has actually
walked a commit root needs the stronger answer.

Add commit_root_confirmed(), true once a call with the flag has
succeeded.  Make the probe state atomic, since other threads now read
it.

Assisted-by: Claude-Code:claude-opus-5-5
include/crucible/fs.h
lib/fs.cc

index f903a7dfab4183fa1284eb068605e045b9ca1f36..c3755d982cbfbd40b9c7a5578a1ea308fff2e4e1 100644 (file)
@@ -98,6 +98,12 @@ namespace crucible {
                /// whether it does.
                static bool commit_root_supported();
 
+               /// True once a call with BTRFS_LOGICAL_INO_ARGS_COMMIT_ROOT
+               /// has succeeded in this process, proving the kernel walked
+               /// the commit root.  False while support is unknown and when
+               /// it is proven absent.
+               static bool commit_root_confirmed();
+
                struct BtrfsInodeOffsetRootSpan {
                        using iterator = BtrfsInodeOffsetRoot*;
                        using const_iterator = const BtrfsInodeOffsetRoot*;
index 1edee61abbd8afb3dc7360db033693962ae3da0d..9f8e9c7ae18ecda93aa216d0221e55d4f286dcb2 100644 (file)
--- a/lib/fs.cc
+++ b/lib/fs.cc
@@ -10,6 +10,7 @@
 // FS_IOC_FIEMAP
 #include <linux/fs.h>
 
+#include <atomic>
 #include <cassert>
 #include <cstddef>
 #include <iostream>
@@ -351,15 +352,16 @@ namespace crucible {
        /// supported once a call with it succeeds, and known unsupported only
        /// when a call with it fails with EINVAL and an immediate repeat of the
        /// same call without it succeeds.  A kernel will not learn the flag
-       /// while this process runs, so both conclusions are permanent.  Raced
-       /// like bili_version below, and harmlessly:  racing threads can only
-       /// repeat a probe, and every probe on one kernel reaches the same answer.
+       /// while this process runs, so both conclusions are permanent.  Racing
+       /// threads can only repeat a probe, and every probe on one kernel
+       /// reaches the same answer.  Atomic because other threads read the
+       /// answer through commit_root_supported() and commit_root_confirmed().
        enum BiliCommitRoot {
                BILI_COMMIT_ROOT_UNKNOWN,
                BILI_COMMIT_ROOT_SUPPORTED,
                BILI_COMMIT_ROOT_UNSUPPORTED,
        };
-       static BiliCommitRoot bili_commit_root = BILI_COMMIT_ROOT_UNKNOWN;
+       static atomic<BiliCommitRoot> bili_commit_root(BILI_COMMIT_ROOT_UNKNOWN);
 
        bool
        BtrfsIoctlLogicalInoArgs::commit_root_supported()
@@ -367,6 +369,12 @@ namespace crucible {
                return bili_commit_root != BILI_COMMIT_ROOT_UNSUPPORTED;
        }
 
+       bool
+       BtrfsIoctlLogicalInoArgs::commit_root_confirmed()
+       {
+               return bili_commit_root == BILI_COMMIT_ROOT_SUPPORTED;
+       }
+
        bool
        BtrfsIoctlLogicalInoArgs::do_ioctl_nothrow(int fd)
        {