GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/fuse_evict.h
Date: 2026-10-25 02:40:14
Exec Total Coverage
Lines: 7 7 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_FUSE_EVICT_H_
6 #define CVMFS_FUSE_EVICT_H_
7
8 #include <pthread.h>
9 #include <stdint.h>
10
11 #include <atomic>
12
13 #include "bigvector.h"
14 #include "duplex_fuse.h"
15 #include "duplex_testing.h"
16 #include "shortstring.h"
17 #include "util/concurrency.h"
18 #include "util/single_copy.h"
19
20 namespace glue {
21 class InodeTracker;
22 class DentryTracker;
23 } // namespace glue
24
25 class MountPoint;
26
27 /**
28 * This class can poke all known dentries out of the kernel caches. This allows
29 * for faster remount/reload of the fuse module because caches don't need to
30 * drain out by timeout. If the fuse library doesn't provide
31 * fuse_lowlevel_notify_inval_entry, it falls back to waiting for drainout.
32 *
33 * Evicting entries from the cache must be done from a separate thread to
34 * avoid a deadlock in the fuse callbacks (see Fuse documentation).
35 */
36 class FuseInvalidator : SingleCopy {
37 friend class T_FuseInvalidator; // for T_FuseInvalidator.SetUp()
38 FRIEND_TEST(T_FuseInvalidator, StartStop);
39 FRIEND_TEST(T_FuseInvalidator, InvalidateTimeout);
40 FRIEND_TEST(T_FuseInvalidator, InvalidateOps);
41
42 public:
43 static bool HasFuseNotifyInval();
44
45 /**
46 * Used to track the progress of an "invalidation" request. The invalidator
47 * will evict cache entries for a duration given by the timeout. For very
48 * large caches, active eviction can take longer than the timeout.
49 *
50 * The caller needs to keep Handle active until IsDone() is true;
51 */
52 class Handle : SingleCopy {
53 friend class FuseInvalidator;
54
55 public:
56 explicit Handle(unsigned timeout_s);
57 ~Handle();
58 378 bool IsDone() const { return status_->load() == 1; }
59 9 void Reset() { status_->store(0); }
60 void WaitFor();
61
62 private:
63 45 void SetDone() {
64 45 int32_t expected_val = 0;
65 45 status_->compare_exchange_strong(expected_val, 1);
66 45 }
67
68 unsigned timeout_s_;
69 std::atomic<int32_t> *status_;
70 };
71
72 struct Command {
73 162 virtual ~Command() { }
74 };
75 struct QuitCommand : public Command { };
76 struct InvalInodesCommand : public Command {
77 Handle *handle;
78 };
79 struct InvalDentryCommand : public Command {
80 uint64_t parent_ino;
81 NameString name;
82 };
83
84 FuseInvalidator(MountPoint *mountpoint,
85 struct fuse_session **fuse_session,
86 bool fuse_notify_invalidation);
87 ~FuseInvalidator();
88 void Spawn();
89 void InvalidateInodes(Handle *handle);
90
91 void InvalidateDentry(uint64_t parent_ino, const NameString &name);
92
93 private:
94 /**
95 * CONSTRUCTOR ONLY FOR UNITTESTS - mountpoint will illegally be null
96 * ( we do not want to construct a full mountpoint in the unittest )
97 */
98 FuseInvalidator(glue::InodeTracker *inode_tracker,
99 glue::DentryTracker *dentry_tracker,
100 struct fuse_session **fuse_session,
101 bool fuse_notify_invalidation);
102 /**
103 * Add one second to the caller-provided timeout to be on the safe side.
104 */
105 static const unsigned kTimeoutSafetyMarginSec; // = 1;
106 /**
107 * If caches are drained out by timeout, set a polling interval.
108 */
109 static const unsigned kCheckTimeoutFreqMs; // = 100;
110 /**
111 * If caches are actively drained out, check every so many operations if the
112 * caches are anyway drained out by timeout.
113 */
114 static const unsigned kCheckTimeoutFreqOps; // = 256
115
116 static void *MainInvalidator(void *data);
117
118 MountPoint *mount_point_;
119
120 glue::InodeTracker *inode_tracker_;
121 glue::DentryTracker *dentry_tracker_;
122 struct fuse_session **fuse_session_;
123 bool spawned_;
124 Channel<Command> channel_;
125 pthread_t thread_invalidator_;
126 /**
127 * An invalidation run can take some time. Allow for early cancellation if
128 * thread should be shut down.
129 */
130 std::atomic<int32_t> terminated_;
131 BigVector<uint64_t> evict_list_;
132
133 static bool g_fuse_notify_invalidation_;
134 }; // class FuseInvalidator
135
136 #endif // CVMFS_FUSE_EVICT_H_
137
138