]> git.hungrycats.org Git - bees/commitdiff
fs: add a runtime debug stream for btrfs tree searches
authorZygo Blaxell <bees@furryterror.org>
Sun, 2 Feb 2025 17:25:50 +0000 (12:25 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 7 Feb 2025 03:42:15 +0000 (22:42 -0500)
This allows plugging in an ostream at run time so that we can audit all
the search calls we are doing.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
include/crucible/fs.h
lib/fs.cc

index 9c843d8f7b969ee6e474a7cffb6f4100584e1f85..8dfdf921a3276688ac1eb93c80d38ad0eb519716 100644 (file)
@@ -201,6 +201,7 @@ namespace crucible {
                static thread_local size_t s_calls;
                static thread_local size_t s_loops;
                static thread_local size_t s_loops_empty;
+               static thread_local shared_ptr<ostream> s_debug_ostream;
        };
 
        ostream & operator<<(ostream &os, const btrfs_ioctl_search_key &key);
index dc20318796e1c6acfd9c35c3f478e0564ecfa907..25443c8d22f39b1fc101d4710937f25589396a76 100644 (file)
--- a/lib/fs.cc
+++ b/lib/fs.cc
@@ -757,6 +757,7 @@ namespace crucible {
        thread_local size_t BtrfsIoctlSearchKey::s_calls = 0;
        thread_local size_t BtrfsIoctlSearchKey::s_loops = 0;
        thread_local size_t BtrfsIoctlSearchKey::s_loops_empty = 0;
+       thread_local shared_ptr<ostream> BtrfsIoctlSearchKey::s_debug_ostream;
 
        bool
        BtrfsIoctlSearchKey::do_ioctl_nothrow(int fd)
@@ -776,6 +777,9 @@ namespace crucible {
                        ioctl_ptr = ioctl_arg.get<btrfs_ioctl_search_args_v2>();
                        ioctl_ptr->key = static_cast<const btrfs_ioctl_search_key&>(*this);
                        ioctl_ptr->buf_size = buf_size;
+                       if (s_debug_ostream) {
+                               (*s_debug_ostream) << "bisk " << (ioctl_ptr->key) << "\n";
+                       }
                        // Don't bother supporting V1.  Kernels that old have other problems.
                        int rv = ioctl(fd, BTRFS_IOC_TREE_SEARCH_V2, ioctl_arg.data());
                        ++s_calls;