GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/compat.cc
Date: 2025-06-22 02:36:02
Exec Total Coverage
Lines: 0 140 0.0%
Branches: 0 124 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include "compat.h"
7
8 #include <cstdlib>
9 #include <cstring>
10
11 #include "crypto/hash.h"
12
13 using namespace std; // NOLINT
14
15 namespace compat {
16
17 namespace shash_v1 {
18
19 const char *kSuffixes[] = {"", "", "-rmd160", ""};
20
21 Md5::Md5(const char *chars, const unsigned length) {
22 ::shash::Md5 new_md5(chars, length);
23
24 algorithm = kMd5;
25 memcpy(new_md5.digest, digest, kDigestSizes[kMd5]);
26 }
27
28 void MigrateAny(const Any *old_hash, shash::Any *new_hash) {
29 memcpy(new_hash->digest, old_hash->digest, kDigestSizes[kAny]);
30 new_hash->algorithm = shash::Algorithms(old_hash->algorithm);
31 new_hash->suffix = shash::kSuffixNone;
32 }
33
34 } // namespace shash_v1
35
36
37 //------------------------------------------------------------------------------
38
39
40 namespace shash_v2 {
41
42 const char *kSuffixes[] = {"", "", "-rmd160", ""};
43
44 void MigrateAny(const Any *old_hash, shash::Any *new_hash) {
45 memcpy(new_hash->digest, old_hash->digest, kDigestSizes[kAny]);
46 new_hash->algorithm = shash::Algorithms(old_hash->algorithm);
47 new_hash->suffix = old_hash->suffix;
48 }
49
50 } // namespace shash_v2
51
52
53 //------------------------------------------------------------------------------
54
55
56 namespace inode_tracker {
57
58 bool InodeContainer::ConstructPath(const uint64_t inode, PathString *path) {
59 const InodeMap::const_iterator needle = map_.find(inode);
60 if (needle == map_.end())
61 return false;
62
63 if (needle->second.name.IsEmpty())
64 return true;
65
66 const bool retval = ConstructPath(needle->second.parent_inode, path);
67 path->Append("/", 1);
68 path->Append(needle->second.name.GetChars(), needle->second.name.GetLength());
69 assert(retval);
70 return retval;
71 }
72
73
74 InodeTracker::~InodeTracker() {
75 pthread_mutex_destroy(lock_);
76 free(lock_);
77 }
78
79 void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker) {
80 InodeContainer::InodeMap::const_iterator i, iEnd;
81 i = old_tracker->inode2path_.map_.begin();
82 iEnd = old_tracker->inode2path_.map_.end();
83 for (; i != iEnd; ++i) {
84 const uint64_t inode = i->first;
85 const uint32_t references = i->second.references;
86 PathString path;
87 old_tracker->inode2path_.ConstructPath(inode, &path);
88 new_tracker->VfsGetBy(glue::InodeEx(inode, glue::InodeEx::kUnknownType),
89 references, path);
90 }
91 }
92
93 } // namespace inode_tracker
94
95
96 //------------------------------------------------------------------------------
97
98
99 namespace inode_tracker_v2 {
100
101 static uint32_t hasher_md5(const shash_v1::Md5 &key) {
102 return (uint32_t) * ((uint32_t *)key.digest + 1); // NOLINT
103 }
104
105 static uint32_t hasher_inode(const uint64_t &inode) {
106 return MurmurHash2(&inode, sizeof(inode), 0x07387a4f);
107 }
108
109 void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker) {
110 old_tracker->inode_map_.map_.hasher_ = hasher_inode;
111 old_tracker->path_map_.map_.hasher_ = hasher_md5;
112
113 SmallHashDynamic<uint64_t, uint32_t>
114 *old_inodes = &old_tracker->inode_references_.map_;
115 for (unsigned i = 0; i < old_inodes->capacity_; ++i) {
116 const uint64_t inode = old_inodes->keys_[i];
117 if (inode == 0)
118 continue;
119
120 const uint32_t references = old_inodes->values_[i];
121 PathString path;
122 const bool retval = old_tracker->FindPath(inode, &path);
123 assert(retval);
124 new_tracker->VfsGetBy(glue::InodeEx(inode, glue::InodeEx::kUnknownType),
125 references, path);
126 }
127 }
128
129 } // namespace inode_tracker_v2
130
131
132 //------------------------------------------------------------------------------
133
134
135 namespace inode_tracker_v3 {
136
137 static uint32_t hasher_md5(const shash_v1::Md5 &key) {
138 return (uint32_t) * ((uint32_t *)key.digest + 1); // NOLINT
139 }
140
141 static uint32_t hasher_inode(const uint64_t &inode) {
142 return MurmurHash2(&inode, sizeof(inode), 0x07387a4f);
143 }
144
145 void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker) {
146 old_tracker->inode_map_.map_.SetHasher(hasher_inode);
147 old_tracker->path_map_.map_.SetHasher(hasher_md5);
148 old_tracker->path_map_.path_store_.map_.SetHasher(hasher_md5);
149
150 SmallHashDynamic<uint64_t, uint32_t>
151 *old_inodes = &old_tracker->inode_references_.map_;
152 for (unsigned i = 0; i < old_inodes->capacity(); ++i) {
153 const uint64_t inode = old_inodes->keys()[i];
154 if (inode == 0)
155 continue;
156
157 const uint32_t references = old_inodes->values()[i];
158 PathString path;
159 const bool retval = old_tracker->FindPath(inode, &path);
160 assert(retval);
161 new_tracker->VfsGetBy(glue::InodeEx(inode, glue::InodeEx::kUnknownType),
162 references, path);
163 }
164 }
165
166 } // namespace inode_tracker_v3
167
168
169 //------------------------------------------------------------------------------
170
171
172 namespace chunk_tables {
173
174 ChunkTables::~ChunkTables() {
175 pthread_mutex_destroy(lock);
176 free(lock);
177 for (unsigned i = 0; i < kNumHandleLocks; ++i) {
178 pthread_mutex_destroy(handle_locks.At(i));
179 free(handle_locks.At(i));
180 }
181 }
182
183 void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
184 new_tables->next_handle = old_tables->next_handle;
185 new_tables->handle2fd = old_tables->handle2fd;
186 new_tables->inode2references = old_tables->inode2references;
187
188 SmallHashDynamic<uint64_t, FileChunkReflist>
189 *old_inode2chunks = &old_tables->inode2chunks;
190 for (unsigned keyno = 0; keyno < old_inode2chunks->capacity(); ++keyno) {
191 const uint64_t inode = old_inode2chunks->keys()[keyno];
192 if (inode == 0)
193 continue;
194
195 FileChunkReflist *old_reflist = &old_inode2chunks->values()[keyno];
196 BigVector<FileChunk> *old_list = old_reflist->list;
197 FileChunkList *new_list = new FileChunkList();
198 for (unsigned i = 0; i < old_list->size(); ++i) {
199 const FileChunk *old_chunk = old_list->AtPtr(i);
200 const off_t offset = old_chunk->offset();
201 const size_t size = old_chunk->size();
202 shash::Any hash;
203 shash_v1::MigrateAny(&old_chunk->content_hash_, &hash);
204 new_list->PushBack(::FileChunk(hash, offset, size));
205 }
206 delete old_list;
207 const ::FileChunkReflist new_reflist(new_list, old_reflist->path,
208 zlib::kZlibDefault, false);
209 new_tables->inode2chunks.Insert(inode, new_reflist);
210 }
211 }
212
213 } // namespace chunk_tables
214
215
216 //------------------------------------------------------------------------------
217
218
219 namespace chunk_tables_v2 {
220
221 ChunkTables::~ChunkTables() {
222 pthread_mutex_destroy(lock);
223 free(lock);
224 for (unsigned i = 0; i < kNumHandleLocks; ++i) {
225 pthread_mutex_destroy(handle_locks.At(i));
226 free(handle_locks.At(i));
227 }
228 }
229
230 void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
231 new_tables->next_handle = old_tables->next_handle;
232 new_tables->handle2fd = old_tables->handle2fd;
233 new_tables->inode2references = old_tables->inode2references;
234
235 SmallHashDynamic<uint64_t, FileChunkReflist>
236 *old_inode2chunks = &old_tables->inode2chunks;
237 for (unsigned keyno = 0; keyno < old_inode2chunks->capacity(); ++keyno) {
238 const uint64_t inode = old_inode2chunks->keys()[keyno];
239 if (inode == 0)
240 continue;
241
242 FileChunkReflist *old_reflist = &old_inode2chunks->values()[keyno];
243 BigVector<FileChunk> *old_list = old_reflist->list;
244 FileChunkList *new_list = new FileChunkList();
245 for (unsigned i = 0; i < old_list->size(); ++i) {
246 const FileChunk *old_chunk = old_list->AtPtr(i);
247 const off_t offset = old_chunk->offset();
248 const size_t size = old_chunk->size();
249 shash::Any hash;
250 shash_v2::MigrateAny(&old_chunk->content_hash_, &hash);
251 new_list->PushBack(::FileChunk(hash, offset, size));
252 }
253 delete old_list;
254 const ::FileChunkReflist new_reflist(new_list, old_reflist->path,
255 zlib::kZlibDefault, false);
256 new_tables->inode2chunks.Insert(inode, new_reflist);
257 }
258 }
259
260 } // namespace chunk_tables_v2
261
262
263 //------------------------------------------------------------------------------
264
265
266 namespace chunk_tables_v3 {
267
268 ChunkTables::~ChunkTables() {
269 pthread_mutex_destroy(lock);
270 free(lock);
271 for (unsigned i = 0; i < kNumHandleLocks; ++i) {
272 pthread_mutex_destroy(handle_locks.At(i));
273 free(handle_locks.At(i));
274 }
275 }
276
277 void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
278 new_tables->next_handle = old_tables->next_handle;
279 new_tables->handle2fd = old_tables->handle2fd;
280 new_tables->inode2chunks = old_tables->inode2chunks;
281 new_tables->inode2references = old_tables->inode2references;
282 }
283
284 } // namespace chunk_tables_v3
285
286 } // namespace compat
287