GCC Code Coverage Report


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