GCC Code Coverage Report


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