GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/lru_md.h
Date: 2026-05-10 02:36:07
Exec Total Coverage
Lines: 29 62 46.8%
Branches: 20 46 43.5%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 *
4 * Provides the LRU sub classes used for the file system client meta-data cache
5 */
6
7 #ifndef CVMFS_LRU_MD_H_
8 #define CVMFS_LRU_MD_H_
9
10 #include <stdint.h>
11
12 #include "crypto/hash.h"
13 #include "directory_entry.h"
14 #include "duplex_fuse.h"
15 #include "lru.h"
16 #include "shortstring.h"
17 #include "util/atomic.h"
18 #include "util/logging.h"
19 #include "util/murmur.hxx"
20
21
22 namespace lru {
23
24 // Hash functions
25 466 static inline uint32_t hasher_md5(const shash::Md5 &key) {
26 // Don't start with the first bytes, because == is using them as well
27 return static_cast<uint32_t>(
28 466 *(reinterpret_cast<const uint32_t *>(key.digest) + 1));
29 }
30
31 static inline uint32_t hasher_inode(const fuse_ino_t &inode) {
32 return MurmurHash2(&inode, sizeof(inode), 0x07387a4f);
33 }
34 // uint32_t hasher_md5(const shash::Md5 &key);
35 // uint32_t hasher_inode(const fuse_ino_t &inode);
36
37
38 class InodeCache : public LruCache<fuse_ino_t, catalog::DirectoryEntry> {
39 public:
40 199 explicit InodeCache(unsigned int cache_size, perf::Statistics *statistics)
41 199 : LruCache<fuse_ino_t, catalog::DirectoryEntry>(
42 cache_size, fuse_ino_t(-1), hasher_inode,
43
3/6
✓ Branch 2 taken 199 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 199 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 199 times.
✗ Branch 9 not taken.
199 perf::StatisticsTemplate("inode_cache", statistics)) { }
44
45 bool Insert(const fuse_ino_t &inode, const catalog::DirectoryEntry &dirent) {
46 LogCvmfs(kLogLru, kLogDebug, "insert inode --> dirent: %lu -> '%s'", inode,
47 dirent.name().c_str());
48 const bool result = LruCache<fuse_ino_t, catalog::DirectoryEntry>::Insert(
49 inode, dirent);
50 return result;
51 }
52
53 bool Lookup(const fuse_ino_t &inode, catalog::DirectoryEntry *dirent,
54 bool update_lru = true) {
55 const bool result = LruCache<fuse_ino_t, catalog::DirectoryEntry>::Lookup(
56 inode, dirent);
57 LogCvmfs(kLogLru, kLogDebug, "lookup inode --> dirent: %lu (%s)", inode,
58 result ? "hit" : "miss");
59 return result;
60 }
61
62 void Drop() {
63 LogCvmfs(kLogLru, kLogDebug, "dropping inode cache");
64 LruCache<fuse_ino_t, catalog::DirectoryEntry>::Drop();
65 }
66 }; // InodeCache
67
68
69 class PathCache : public LruCache<fuse_ino_t, PathString> {
70 public:
71 199 explicit PathCache(unsigned int cache_size, perf::Statistics *statistics)
72 199 : LruCache<fuse_ino_t, PathString>(
73 cache_size, fuse_ino_t(-1), hasher_inode,
74
3/6
✓ Branch 2 taken 199 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 199 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 199 times.
✗ Branch 9 not taken.
199 perf::StatisticsTemplate("path_cache", statistics)) { }
75
76 bool Insert(const fuse_ino_t &inode, const PathString &path) {
77 LogCvmfs(kLogLru, kLogDebug, "insert inode --> path %lu -> '%s'", inode,
78 path.c_str());
79 const bool result = LruCache<fuse_ino_t, PathString>::Insert(inode, path);
80 return result;
81 }
82
83 bool Lookup(const fuse_ino_t &inode, PathString *path,
84 bool update_lru = true) {
85 const bool found = LruCache<fuse_ino_t, PathString>::Lookup(inode, path);
86 LogCvmfs(kLogLru, kLogDebug, "lookup inode --> path: %lu (%s)", inode,
87 found ? "hit" : "miss");
88 return found;
89 }
90
91 void Drop() {
92 LogCvmfs(kLogLru, kLogDebug, "dropping path cache");
93 LruCache<fuse_ino_t, PathString>::Drop();
94 }
95 }; // PathCache
96
97
98 class Md5PathCache : public LruCache<shash::Md5, catalog::DirectoryEntry> {
99 public:
100 245 explicit Md5PathCache(unsigned int cache_size, perf::Statistics *statistics)
101 245 : LruCache<shash::Md5, catalog::DirectoryEntry>(
102
2/4
✓ Branch 2 taken 245 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 245 times.
✗ Branch 7 not taken.
490 cache_size, shash::Md5(shash::AsciiPtr("!")), hasher_md5,
103
4/8
✓ Branch 2 taken 245 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 245 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 245 times.
✗ Branch 9 not taken.
✓ Branch 14 taken 245 times.
✗ Branch 15 not taken.
735 perf::StatisticsTemplate("md5_path_cache", statistics)) {
104
2/4
✓ Branch 1 taken 245 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 245 times.
✗ Branch 5 not taken.
245 dirent_negative_ = catalog::DirectoryEntry(catalog::kDirentNegative);
105 245 }
106
107 126 bool Insert(const shash::Md5 &hash, const catalog::DirectoryEntry &dirent) {
108
1/2
✓ Branch 3 taken 126 times.
✗ Branch 4 not taken.
252 LogCvmfs(kLogLru, kLogDebug, "insert md5 --> dirent: %s -> '%s'",
109
1/2
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
378 hash.ToString().c_str(), dirent.name().c_str());
110 126 const bool result = LruCache<shash::Md5, catalog::DirectoryEntry>::Insert(
111 hash, dirent);
112 126 return result;
113 }
114
115 15 bool InsertNegative(const shash::Md5 &hash) {
116 15 const bool result = Insert(hash, dirent_negative_);
117
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (result)
118 15 perf::Inc(counters_.n_insert_negative);
119 15 return result;
120 }
121
122 214 bool Lookup(const shash::Md5 &hash, catalog::DirectoryEntry *dirent,
123 bool update_lru = true) {
124 214 const bool result = LruCache<shash::Md5, catalog::DirectoryEntry>::Lookup(
125 hash, dirent);
126
3/4
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 126 times.
✓ Branch 4 taken 214 times.
✗ Branch 5 not taken.
428 LogCvmfs(kLogLru, kLogDebug, "lookup md5 --> dirent: %s (%s)",
127 428 hash.ToString().c_str(), result ? "hit" : "miss");
128 214 return result;
129 }
130
131 bool Forget(const shash::Md5 &hash) {
132 LogCvmfs(kLogLru, kLogDebug, "forget md5: %s", hash.ToString().c_str());
133 return LruCache<shash::Md5, catalog::DirectoryEntry>::Forget(hash);
134 }
135
136 void Drop() {
137 LogCvmfs(kLogLru, kLogDebug, "dropping md5path cache");
138 LruCache<shash::Md5, catalog::DirectoryEntry>::Drop();
139 }
140
141 private:
142 catalog::DirectoryEntry dirent_negative_;
143 }; // Md5PathCache
144
145 } // namespace lru
146
147 #endif // CVMFS_LRU_MD_H_
148