GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/fd_refcount_mgr.h
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 1 6 16.7%
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 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 return *const_cast<uint32_t *>(
19 reinterpret_cast<const uint32_t *>(key.digest) + 1);
20 }
21 static inline uint32_t hasher_int(const int &key) {
22 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 3549 FdRefcountInfo(): refcount(-1) { }
35 };
36
37 FdRefcountMgr();
38
39 ~FdRefcountMgr();
40
41 FdRefcountMgr(
42 const SmallHashDynamic<int, FdRefcountInfo> &map_refcount,
43 const SmallHashDynamic<shash::Any, int> &map_fd);
44
45 void AssignFrom(FdRefcountMgr *other);
46
47 SmallHashDynamic<int, FdRefcountInfo>* GetRefcountMapPtr();
48
49 SmallHashDynamic<shash::Any, int>* GetFdMapPtr();
50
51 int Open(const shash::Any id, const std::string& path);
52
53 int Close(int fd);
54
55 int Dup(int fd);
56
57 FdRefcountMgr* Clone();
58
59 private:
60 /**
61 * map for fd -> refcount lookups. A backreference
62 * to the object id is included in FdRefcountInfo in order
63 * to be able to remove the file descriptor from map_fd_.
64 */
65 SmallHashDynamic<int, FdRefcountInfo> map_refcount_;
66 /**
67 * map for object id -> fd lookups, used when
68 * opening files in the cache. The fd is used as key
69 * in the refcount map.
70 */
71 SmallHashDynamic<shash::Any, int> map_fd_;
72 pthread_mutex_t *lock_cache_refcount_;
73 };
74
75 #endif // CVMFS_FD_REFCOUNT_MGR_H_
76