GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/fd_refcount_mgr.h
Date: 2025-11-30 02:35:17
Exec Total Coverage
Lines: 6 6 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_FD_REFCOUNT_MGR_H_
6 #define CVMFS_FD_REFCOUNT_MGR_H_
7
8 #include <string>
9
10 #include "cache.h"
11 #include "smallhash.h"
12
13
14 // for map of file descriptors; as in kvstore.cc
15 3466 static inline uint32_t hasher_any(const shash::Any &key) {
16 // We'll just do the same thing as hasher_md5, since every hash is at
17 // least as large.
18 3466 return *const_cast<uint32_t *>(reinterpret_cast<const uint32_t *>(key.digest)
19 3466 + 1);
20 }
21 3262 static inline uint32_t hasher_int(const int &key) {
22 3262 return MurmurHash2(&key, sizeof(key), 0x07387a4f);
23 }
24
25 class ListOpenHashesMagicXattr; // FD needed to access fd_mgr_
26 class FdRefcountMgr {
27 friend class ListOpenHashesMagicXattr;
28
29 public:
30 /**
31 * Helper class containing the values for the map: fd -> refcount+id
32 */
33 struct FdRefcountInfo {
34 int refcount; /// refcount for the times the fd was opened in the cache
35 shash::Any id; /// hash of the object opened through the fd
36
37 40194 FdRefcountInfo() : refcount(-1) { }
38 };
39
40 FdRefcountMgr();
41
42 ~FdRefcountMgr();
43
44 FdRefcountMgr(const SmallHashDynamic<int, FdRefcountInfo> &map_refcount,
45 const SmallHashDynamic<shash::Any, int> &map_fd);
46
47 void AssignFrom(FdRefcountMgr *other);
48
49 SmallHashDynamic<int, FdRefcountInfo> *GetRefcountMapPtr();
50
51 SmallHashDynamic<shash::Any, int> *GetFdMapPtr();
52
53 int Open(const shash::Any id, const std::string &path);
54
55 int Close(int fd);
56
57 int Dup(int fd);
58
59 FdRefcountMgr *Clone();
60
61 private:
62 /**
63 * map for fd -> refcount lookups. A backreference
64 * to the object id is included in FdRefcountInfo in order
65 * to be able to remove the file descriptor from map_fd_.
66 */
67 SmallHashDynamic<int, FdRefcountInfo> map_refcount_;
68 /**
69 * map for object id -> fd lookups, used when
70 * opening files in the cache. The fd is used as key
71 * in the refcount map.
72 */
73 SmallHashDynamic<shash::Any, int> map_fd_;
74 pthread_mutex_t *lock_cache_refcount_;
75 };
76
77 #endif // CVMFS_FD_REFCOUNT_MGR_H_
78
79