GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/fd_refcount_mgr.h
Date: 2025-06-22 02:36:02
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 8387 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 8387 return *const_cast<uint32_t *>(reinterpret_cast<const uint32_t *>(key.digest)
19 8387 + 1);
20 }
21 7408 static inline uint32_t hasher_int(const int &key) {
22 7408 return MurmurHash2(&key, sizeof(key), 0x07387a4f);
23 }
24
25 class FdRefcountMgr {
26 public:
27 /**
28 * Helper class containing the values for the map: fd -> refcount+id
29 */
30 struct FdRefcountInfo {
31 int refcount; /// refcount for the times the fd was opened in the cache
32 shash::Any id; /// hash of the object opened through the fd
33
34 77586 FdRefcountInfo() : refcount(-1) { }
35 };
36
37 FdRefcountMgr();
38
39 ~FdRefcountMgr();
40
41 FdRefcountMgr(const SmallHashDynamic<int, FdRefcountInfo> &map_refcount,
42 const SmallHashDynamic<shash::Any, int> &map_fd);
43
44 void AssignFrom(FdRefcountMgr *other);
45
46 SmallHashDynamic<int, FdRefcountInfo> *GetRefcountMapPtr();
47
48 SmallHashDynamic<shash::Any, int> *GetFdMapPtr();
49
50 int Open(const shash::Any id, const std::string &path);
51
52 int Close(int fd);
53
54 int Dup(int fd);
55
56 FdRefcountMgr *Clone();
57
58 private:
59 /**
60 * map for fd -> refcount lookups. A backreference
61 * to the object id is included in FdRefcountInfo in order
62 * to be able to remove the file descriptor from map_fd_.
63 */
64 SmallHashDynamic<int, FdRefcountInfo> map_refcount_;
65 /**
66 * map for object id -> fd lookups, used when
67 * opening files in the cache. The fd is used as key
68 * in the refcount map.
69 */
70 SmallHashDynamic<shash::Any, int> map_fd_;
71 pthread_mutex_t *lock_cache_refcount_;
72 };
73
74 #endif // CVMFS_FD_REFCOUNT_MGR_H_
75