GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/nfs_maps_leveldb.h
Date: 2025-07-13 02:35:07
Exec Total Coverage
Lines: 0 1 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_NFS_MAPS_LEVELDB_H_
6 #define CVMFS_NFS_MAPS_LEVELDB_H_
7
8 #include <pthread.h>
9
10 #include <string>
11
12 #include "crypto/hash.h"
13 #include "leveldb/env.h"
14 #include "nfs_maps.h"
15 #include "util/atomic.h"
16
17
18 namespace leveldb {
19 class DB;
20 class Cache;
21 class FilterPolicy;
22 } // namespace leveldb
23 namespace perf {
24 class Counter;
25 class Statistics;
26 } // namespace perf
27
28
29 class NfsMapsLeveldb : public NfsMaps {
30 public:
31 virtual ~NfsMapsLeveldb();
32 virtual uint64_t GetInode(const PathString &path);
33 virtual bool GetPath(const uint64_t inode, PathString *path);
34 virtual void SetInodeResidue(unsigned residue_class, unsigned remainder);
35 virtual void Spawn() { spawned_ = true; }
36 virtual std::string GetStatistics();
37
38 static NfsMapsLeveldb *Create(const std::string &leveldb_dir,
39 const uint64_t root_inode,
40 const bool rebuild,
41 perf::Statistics *statistics);
42
43 private:
44 class ForkAwareEnv;
45 struct FuncArg {
46 void (*function)(void *);
47 void *arg;
48 class ForkAwareEnv *env;
49 };
50
51 /**
52 * Leveldb's background threads must not be started before cvmfs has forked.
53 * Before forking, we run the processes in specially created threads.
54 * We make sure, these threads are terminated before forking.
55 */
56 class ForkAwareEnv : public leveldb::EnvWrapper {
57 public:
58 explicit ForkAwareEnv(NfsMapsLeveldb *maps);
59 void StartThread(void (*f)(void *), void *a);
60 void Schedule(void (*function)(void *), void *arg);
61 void WaitForBGThreads();
62 void SleepForMicroseconds(int micros);
63
64 private:
65 static void *MainFakeThread(void *data);
66
67 NfsMapsLeveldb *maps_;
68 atomic_int32 num_bg_threads_;
69 };
70
71 NfsMapsLeveldb();
72 void PutInode2Path(const uint64_t inode, const PathString &path);
73 void PutPath2Inode(const shash::Md5 &path, const uint64_t inode);
74 uint64_t FindInode(const shash::Md5 &path);
75
76 leveldb::DB *db_inode2path_;
77 leveldb::DB *db_path2inode_;
78 leveldb::Cache *cache_inode2path_;
79 leveldb::Cache *cache_path2inode_;
80 const leveldb::FilterPolicy *filter_inode2path_;
81 const leveldb::FilterPolicy *filter_path2inode_;
82 ForkAwareEnv *fork_aware_env_;
83 uint64_t root_inode_;
84 uint64_t seq_;
85 pthread_mutex_t *lock_;
86 bool spawned_;
87
88 unsigned inode_residue_class_;
89 unsigned inode_remainder_;
90
91 perf::Counter *n_db_added_;
92 };
93
94 #endif // CVMFS_NFS_MAPS_LEVELDB_H_
95