GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/compat.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 0 137 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 #include "cvmfs_config.h"
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 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 bool retval = ConstructPath(needle->second.parent_inode, path);
67 path->Append("/", 1);
68 path->Append(needle->second.name.GetChars(),
69 needle->second.name.GetLength());
70 assert(retval);
71 return retval;
72 }
73
74
75 InodeTracker::~InodeTracker() {
76 pthread_mutex_destroy(lock_);
77 free(lock_);
78 }
79
80 void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker) {
81 InodeContainer::InodeMap::const_iterator i, iEnd;
82 i = old_tracker->inode2path_.map_.begin();
83 iEnd = old_tracker->inode2path_.map_.end();
84 for (; i != iEnd; ++i) {
85 uint64_t inode = i->first;
86 uint32_t references = i->second.references;
87 PathString path;
88 old_tracker->inode2path_.ConstructPath(inode, &path);
89 new_tracker->VfsGetBy(
90 glue::InodeEx(inode, glue::InodeEx::kUnknownType), references, path);
91 }
92 }
93
94 } // namespace inode_tracker
95
96
97 //------------------------------------------------------------------------------
98
99
100 namespace inode_tracker_v2 {
101
102 static uint32_t hasher_md5(const shash_v1::Md5 &key) {
103 return (uint32_t) *((uint32_t *)key.digest + 1); // NOLINT
104 }
105
106 static uint32_t hasher_inode(const uint64_t &inode) {
107 return MurmurHash2(&inode, sizeof(inode), 0x07387a4f);
108 }
109
110 void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker) {
111 old_tracker->inode_map_.map_.hasher_ = hasher_inode;
112 old_tracker->path_map_.map_.hasher_ = hasher_md5;
113
114 SmallHashDynamic<uint64_t, uint32_t> *old_inodes =
115 &old_tracker->inode_references_.map_;
116 for (unsigned i = 0; i < old_inodes->capacity_; ++i) {
117 const uint64_t inode = old_inodes->keys_[i];
118 if (inode == 0) continue;
119
120 const uint32_t references = old_inodes->values_[i];
121 PathString path;
122 bool retval = old_tracker->FindPath(inode, &path);
123 assert(retval);
124 new_tracker->VfsGetBy(
125 glue::InodeEx(inode, glue::InodeEx::kUnknownType), 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> *old_inodes =
151 &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) continue;
155
156 const uint32_t references = old_inodes->values()[i];
157 PathString path;
158 bool retval = old_tracker->FindPath(inode, &path);
159 assert(retval);
160 new_tracker->VfsGetBy(
161 glue::InodeEx(inode, glue::InodeEx::kUnknownType), references, path);
162 }
163 }
164
165 } // namespace inode_tracker_v3
166
167
168 //------------------------------------------------------------------------------
169
170
171 namespace chunk_tables {
172
173 ChunkTables::~ChunkTables() {
174 pthread_mutex_destroy(lock);
175 free(lock);
176 for (unsigned i = 0; i < kNumHandleLocks; ++i) {
177 pthread_mutex_destroy(handle_locks.At(i));
178 free(handle_locks.At(i));
179 }
180 }
181
182 void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
183 new_tables->next_handle = old_tables->next_handle;
184 new_tables->handle2fd = old_tables->handle2fd;
185 new_tables->inode2references = old_tables->inode2references;
186
187 SmallHashDynamic<uint64_t, FileChunkReflist> *old_inode2chunks =
188 &old_tables->inode2chunks;
189 for (unsigned keyno = 0; keyno < old_inode2chunks->capacity(); ++keyno) {
190 const uint64_t inode = old_inode2chunks->keys()[keyno];
191 if (inode == 0) continue;
192
193 FileChunkReflist *old_reflist = &old_inode2chunks->values()[keyno];
194 BigVector<FileChunk> *old_list = old_reflist->list;
195 FileChunkList *new_list = new FileChunkList();
196 for (unsigned i = 0; i < old_list->size(); ++i) {
197 const FileChunk *old_chunk = old_list->AtPtr(i);
198 off_t offset = old_chunk->offset();
199 size_t size = old_chunk->size();
200 shash::Any hash;
201 shash_v1::MigrateAny(&old_chunk->content_hash_, &hash);
202 new_list->PushBack(::FileChunk(hash, offset, size));
203 }
204 delete old_list;
205 ::FileChunkReflist new_reflist(new_list, old_reflist->path,
206 zlib::kZlibDefault, false);
207 new_tables->inode2chunks.Insert(inode, new_reflist);
208 }
209 }
210
211 } // namespace chunk_tables
212
213
214 //------------------------------------------------------------------------------
215
216
217 namespace chunk_tables_v2 {
218
219 ChunkTables::~ChunkTables() {
220 pthread_mutex_destroy(lock);
221 free(lock);
222 for (unsigned i = 0; i < kNumHandleLocks; ++i) {
223 pthread_mutex_destroy(handle_locks.At(i));
224 free(handle_locks.At(i));
225 }
226 }
227
228 void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
229 new_tables->next_handle = old_tables->next_handle;
230 new_tables->handle2fd = old_tables->handle2fd;
231 new_tables->inode2references = old_tables->inode2references;
232
233 SmallHashDynamic<uint64_t, FileChunkReflist> *old_inode2chunks =
234 &old_tables->inode2chunks;
235 for (unsigned keyno = 0; keyno < old_inode2chunks->capacity(); ++keyno) {
236 const uint64_t inode = old_inode2chunks->keys()[keyno];
237 if (inode == 0) continue;
238
239 FileChunkReflist *old_reflist = &old_inode2chunks->values()[keyno];
240 BigVector<FileChunk> *old_list = old_reflist->list;
241 FileChunkList *new_list = new FileChunkList();
242 for (unsigned i = 0; i < old_list->size(); ++i) {
243 const FileChunk *old_chunk = old_list->AtPtr(i);
244 off_t offset = old_chunk->offset();
245 size_t size = old_chunk->size();
246 shash::Any hash;
247 shash_v2::MigrateAny(&old_chunk->content_hash_, &hash);
248 new_list->PushBack(::FileChunk(hash, offset, size));
249 }
250 delete old_list;
251 ::FileChunkReflist new_reflist(new_list, old_reflist->path,
252 zlib::kZlibDefault, false);
253 new_tables->inode2chunks.Insert(inode, new_reflist);
254 }
255 }
256
257 } // namespace chunk_tables_v2
258
259
260 //------------------------------------------------------------------------------
261
262
263 namespace chunk_tables_v3 {
264
265 ChunkTables::~ChunkTables() {
266 pthread_mutex_destroy(lock);
267 free(lock);
268 for (unsigned i = 0; i < kNumHandleLocks; ++i) {
269 pthread_mutex_destroy(handle_locks.At(i));
270 free(handle_locks.At(i));
271 }
272 }
273
274 void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
275 new_tables->next_handle = old_tables->next_handle;
276 new_tables->handle2fd = old_tables->handle2fd;
277 new_tables->inode2chunks = old_tables->inode2chunks;
278 new_tables->inode2references = old_tables->inode2references;
279 }
280
281 } // namespace chunk_tables_v3
282
283 } // namespace compat
284