GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/catalog_mgr_client.cc
Date: 2026-08-02 02:40:19
Exec Total Coverage
Lines: 212 233 91.0%
Branches: 190 331 57.4%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM file system.
3 */
4
5
6 #include "catalog_mgr_client.h"
7
8 #include <string>
9 #include <vector>
10
11 #include "cache_posix.h"
12 #include "crypto/signature.h"
13 #include "fetch.h"
14 #include "manifest.h"
15 #include "mountpoint.h"
16 #include "quota.h"
17 #include "statistics.h"
18 #include "util/posix.h" // IWYU pragma: keep
19 #include "util/string.h"
20
21 using namespace std; // NOLINT
22
23 namespace catalog {
24
25 /**
26 * Triggered when the catalog is attached (db file opened)
27 */
28 925 void ClientCatalogManager::ActivateCatalog(Catalog *catalog) {
29 const Counters &counters = const_cast<const Catalog *>(catalog)
30 925 ->GetCounters();
31
2/2
✓ Branch 1 taken 773 times.
✓ Branch 2 taken 152 times.
925 if (catalog->IsRoot()) {
32 773 all_inodes_ = counters.GetAllEntries();
33 }
34 925 loaded_inodes_ += counters.GetSelfEntries();
35 925 }
36
37
38 1445 ClientCatalogManager::ClientCatalogManager(MountPoint *mountpoint)
39 : AbstractCatalogManager<Catalog>(mountpoint->statistics())
40
1/2
✓ Branch 1 taken 1445 times.
✗ Branch 2 not taken.
1445 , repo_name_(mountpoint->fqrn())
41 1445 , fetcher_(mountpoint->fetcher())
42 1445 , signature_mgr_(mountpoint->signature_mgr())
43
1/2
✓ Branch 2 taken 1445 times.
✗ Branch 3 not taken.
1445 , workspace_(mountpoint->file_system()->workspace())
44 1445 , offline_mode_(false)
45 1445 , all_inodes_(0)
46 1445 , loaded_inodes_(0)
47
1/2
✓ Branch 1 taken 1445 times.
✗ Branch 2 not taken.
1445 , fixed_root_catalog_()
48 1445 , fixed_alt_root_catalog_(false)
49
2/4
✓ Branch 5 taken 1445 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1445 times.
✗ Branch 9 not taken.
2890 , root_fd_(-1) {
50
1/2
✓ Branch 1 taken 1445 times.
✗ Branch 2 not taken.
1445 LogCvmfs(kLogCatalog, kLogDebug, "constructing client catalog manager");
51
3/6
✓ Branch 3 taken 1445 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 1445 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1445 times.
✗ Branch 11 not taken.
1445 n_certificate_hits_ = mountpoint->statistics()->Register(
52 "cache.n_certificate_hits", "Number of certificate hits");
53
3/6
✓ Branch 3 taken 1445 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 1445 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1445 times.
✗ Branch 11 not taken.
1445 n_certificate_misses_ = mountpoint->statistics()->Register(
54 "cache.n_certificate_misses", "Number of certificate misses");
55 1445 }
56
57
58 5028 ClientCatalogManager::~ClientCatalogManager() {
59 2890 LogCvmfs(kLogCache, kLogDebug, "unpinning / unloading all catalogs");
60
61 5780 for (map<PathString, shash::Any>::iterator i = mounted_catalogs_.begin(),
62 2890 iend = mounted_catalogs_.end();
63
2/2
✓ Branch 1 taken 923 times.
✓ Branch 2 taken 1445 times.
4736 i != iend;
64 1846 ++i) {
65 1846 fetcher_->cache_mgr()->quota_mgr()->Unpin(i->second);
66 }
67 5028 }
68
69
70 925 Catalog *ClientCatalogManager::CreateCatalog(const PathString &mountpoint,
71 const shash::Any &catalog_hash,
72 catalog::Catalog *parent_catalog) {
73 925 mounted_catalogs_[mountpoint] = loaded_catalogs_[mountpoint];
74 925 loaded_catalogs_.erase(mountpoint);
75
1/2
✓ Branch 2 taken 925 times.
✗ Branch 3 not taken.
925 return new Catalog(mountpoint, catalog_hash, parent_catalog);
76 }
77
78
79 106 shash::Any ClientCatalogManager::GetRootHash() {
80 106 ReadLock();
81
1/2
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
106 shash::Any result = mounted_catalogs_[PathString("", 0)];
82 106 Unlock();
83 106 return result;
84 }
85
86
87 /**
88 * Specialized initialization that uses a fixed root hash.
89 *
90 * @returns true - root catalog was successfully mounted
91 * false - otherwise
92 */
93 561 bool ClientCatalogManager::InitFixed(const shash::Any &root_hash,
94 bool alternative_path) {
95
1/2
✓ Branch 2 taken 561 times.
✗ Branch 3 not taken.
561 LogCvmfs(kLogCatalog, kLogDebug, "Initialize catalog with fixed root hash %s",
96 1122 root_hash.ToString().c_str());
97 561 WriteLock();
98 561 fixed_alt_root_catalog_ = alternative_path;
99 561 fixed_root_catalog_ = root_hash;
100
101
1/2
✓ Branch 2 taken 561 times.
✗ Branch 3 not taken.
561 const bool attached = MountCatalog(PathString("", 0), root_hash, NULL);
102 561 Unlock();
103
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 561 times.
561 if (!attached) {
105 LogCvmfs(kLogCatalog, kLogDebug, "failed to initialize fixed root catalog");
106 }
107
108 561 return attached;
109 }
110
111 /**
112 * Gets information about the most recent root catalog, including even if it is
113 * a fixed root catalog. This is needed as Remount() does not know what kind of
114 * root catalog will be remounted.
115 *
116 * Checks the locations: mounted, alien cache and remote (server) and sets the
117 * fields of variable "result". For the most recent catalog the location, hash
118 * and revision number are set.
119 *
120 *
121 * @param [out] result All fields but sqlite_path will be set:
122 * mountpoint, root_ctl_location, root_ctlg_revision, hash
123 * @return kLoadUp2Date - if most recent root catalog is already mounted
124 * kLoadNew - otherwise
125 */
126 417 LoadReturn ClientCatalogManager::GetNewRootCatalogContext(
127 CatalogContext *result) {
128
2/4
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 417 times.
✗ Branch 5 not taken.
417 result->SetMountpoint(PathString("", 0));
129
130 // quick escape if we have a fixed catalog
131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 417 times.
417 if (!fixed_root_catalog_.IsNull()) {
132 result->SetHash(fixed_root_catalog_);
133 result->SetRootCtlgRevision(GetRevisionNoLock());
134
135 // it might or might not be already mounted, but we do not care
136 // as we do no need to download and save the manifest
137 // (see LoadCatalogByHash()) as such we must set the location to this
138 result->SetRootCtlgLocation(kCtlgLocationMounted);
139 offline_mode_ = false;
140
141 // we can do this here as the very first time fixed catalog is loaded it
142 // call directly MountCatalog() and will skip the call to this function
143 // here
144 return catalog::kLoadUp2Date;
145 }
146
147 // 1) Get alien cache root catalog (local)
148
149 // Happens only on init/remount, i.e. quota won't delete a cached catalog
150
1/2
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
417 shash::Any local_newest_hash(shash::kSha1, shash::kSuffixCatalog);
151
1/2
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
417 shash::Any mounted_hash(shash::kSha1, shash::kSuffixCatalog);
152 417 uint64_t local_newest_timestamp = 0;
153 417 uint64_t local_newest_revision = manifest::Breadcrumb::kInvalidRevision;
154
155 417 const manifest::Breadcrumb breadcrumb = fetcher_->cache_mgr()->LoadBreadcrumb(
156
1/2
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
417 repo_name_);
157
3/4
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 360 times.
417 if (breadcrumb.IsValid()) {
158 57 local_newest_hash = breadcrumb.catalog_hash;
159 57 local_newest_timestamp = breadcrumb.timestamp;
160 57 local_newest_revision = breadcrumb.revision;
161
1/2
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
114 LogCvmfs(kLogCache, kLogDebug,
162 "Cached copy publish date %s (hash %s, revision %" PRIu64 ")",
163
1/2
✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
114 StringifyTime(static_cast<int64_t>(local_newest_timestamp), true)
164 .c_str(),
165
1/2
✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
114 local_newest_hash.ToString().c_str(), breadcrumb.revision);
166 } else {
167
1/2
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
360 LogCvmfs(kLogCache, kLogDebug, "Unable to read local checksum %s",
168
1/2
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
720 breadcrumb.ToString().c_str());
169 }
170
171 // 2) Select local newest catalog: mounted vs alien
172
173 417 result->SetRootCtlgLocation(kCtlgLocationBreadcrumb);
174 417 LoadReturn success_code = catalog::kLoadNew;
175
176
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 397 times.
417 if (mounted_catalogs_.size() > 0) {
177 const std::map<PathString, shash::Any>::iterator
178
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 curr_hash_itr = mounted_catalogs_.find(PathString("", 0));
179 20 mounted_hash = curr_hash_itr->second;
180 }
181
182 // We only look for currently loaded catalog if the revision is newer than
183 // the breadcrumb revision and both revision numbers are valid (!= -1ul).
184 417 if ((local_newest_revision <= GetRevisionNoLock()
185
1/2
✓ Branch 0 taken 360 times.
✗ Branch 1 not taken.
360 || local_newest_revision == manifest::Breadcrumb::kInvalidRevision)
186
6/6
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 57 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 397 times.
✓ Branch 5 taken 20 times.
✓ Branch 6 taken 397 times.
777 && mounted_catalogs_.size() > 0) {
187 20 local_newest_hash = mounted_hash;
188 20 local_newest_revision = GetRevisionNoLock();
189 // if needed for integration test 707: breadcrumb_timestamp_newer()
190 20 local_newest_timestamp = GetTimestampNoLock() > local_newest_timestamp
191
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12 times.
20 ? GetTimestampNoLock()
192 : local_newest_timestamp;
193 20 result->SetRootCtlgLocation(kCtlgLocationMounted);
194 20 success_code = catalog::kLoadUp2Date;
195
4/6
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 360 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 397 times.
397 } else if (local_newest_revision == 0 && mounted_catalogs_.size() > 0) {
196 // breadcrumb has no revision
197 // TODO(heretherebedragons) this branch can be removed in future versions
198
199 // revisions are better, but if we dont have any we need to compare by
200 // timestamp (you can have multiple revisions in the same timestamp)
201 if (local_newest_timestamp < GetTimestampNoLock()) {
202 local_newest_hash = mounted_hash;
203 local_newest_revision = GetRevisionNoLock();
204 local_newest_timestamp = GetTimestampNoLock();
205 result->SetRootCtlgLocation(kCtlgLocationMounted);
206 success_code = catalog::kLoadUp2Date;
207 }
208 }
209
210 // 3) Get remote root catalog (fails if remote catalog is older)
211 manifest::Failures manifest_failure;
212 UniquePtr<CachedManifestEnsemble> ensemble(
213
2/4
✓ Branch 2 taken 417 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 417 times.
✗ Branch 7 not taken.
417 new CachedManifestEnsemble(fetcher_->cache_mgr(), this));
214
2/4
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 417 times.
✗ Branch 5 not taken.
417 manifest_failure = manifest::Fetch(
215 417 "", repo_name_, local_newest_timestamp, &local_newest_hash,
216 417 signature_mgr_, fetcher_->download_mgr(), ensemble.weak_ref());
217
218
2/2
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 195 times.
417 if (manifest_failure == manifest::kFailOk) {
219 // server has newest revision or no valid local revision
220 222 if (ensemble->manifest->revision() > local_newest_revision
221
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 173 times.
220 || local_newest_revision == manifest::Breadcrumb::kInvalidRevision
222 // if revision is 0 both local and server, load catalog from server
223 // as local is most likely just "initialized" without valid value
224
6/6
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 39 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 214 times.
✓ Branch 7 taken 8 times.
481 || (ensemble->manifest->revision() == 0
225
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 && local_newest_revision == 0)) {
226 214 result->SetHash(ensemble->manifest->catalog_hash());
227 214 result->SetRootCtlgRevision(ensemble->manifest->revision());
228 214 result->SetRootCtlgLocation(kCtlgLocationServer);
229 214 fixed_alt_root_catalog_ = ensemble->manifest->has_alt_catalog_path();
230
231
1/2
✓ Branch 1 taken 214 times.
✗ Branch 2 not taken.
214 result->TakeManifestEnsemble(
232 214 static_cast<manifest::ManifestEnsemble *>(ensemble.Release()));
233 214 offline_mode_ = false;
234
235 214 return catalog::kLoadNew;
236 }
237 }
238
1/2
✓ Branch 2 taken 203 times.
✗ Branch 3 not taken.
203 LogCvmfs(kLogCache, kLogDebug,
239 "Failed fetch manifest from server: "
240 "manifest too old or server unreachable (%d - %s)",
241 manifest_failure, manifest::Code2Ascii(manifest_failure));
242
243 // total failure: server not reachable and no valid local hash
244
6/6
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 187 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 187 times.
✓ Branch 6 taken 16 times.
203 if ((manifest_failure != manifest::kFailOk) && local_newest_hash.IsNull()) {
245
1/2
✓ Branch 1 taken 187 times.
✗ Branch 2 not taken.
187 LogCvmfs(kLogCache, kLogDebug, "No valid root catalog found!");
246 187 return catalog::kLoadFail;
247 }
248
249 16 if (manifest_failure == manifest::kFailOk
250
5/6
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 8 times.
16 && ensemble->manifest->revision() == local_newest_revision) {
251 8 offline_mode_ = false;
252 } else {
253 8 offline_mode_ = true;
254 }
255 16 result->SetHash(local_newest_hash);
256 16 result->SetRootCtlgRevision(local_newest_revision);
257
258 // for integration test 707: breadcrumb_revision_large()
259
4/8
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
16 if (breadcrumb.IsValid() && breadcrumb.catalog_hash == mounted_hash) {
260 16 success_code = catalog::kLoadUp2Date;
261 }
262
263 16 return success_code;
264 417 }
265
266 1065 std::string ClientCatalogManager::GetCatalogDescription(
267 const PathString &mountpoint, const shash::Any &hash) {
268
2/4
✓ Branch 1 taken 1065 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1065 times.
✗ Branch 5 not taken.
2130 return "file catalog at " + repo_name_ + ":"
269
2/4
✓ Branch 1 taken 1065 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1065 times.
✗ Branch 5 not taken.
3195 + (mountpoint.IsEmpty()
270
8/14
✓ Branch 0 taken 789 times.
✓ Branch 1 taken 276 times.
✓ Branch 4 taken 789 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 276 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 276 times.
✓ Branch 13 taken 789 times.
✓ Branch 15 taken 789 times.
✓ Branch 16 taken 276 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2406 ? "/"
271 276 : string(mountpoint.GetChars(), mountpoint.GetLength()))
272
3/6
✓ Branch 2 taken 1065 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1065 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1065 times.
✗ Branch 9 not taken.
4260 + " (" + hash.ToString() + ")";
273 }
274
275 /**
276 * Loads (and fetches) a catalog by hash for a given mountpoint.
277 *
278 * Special case for root catalog: ctlg_context->root_ctlg_location must be
279 * given.
280 *
281 * @param [in, out] ctlg_context mandatory fields (input): mountpoint, hash
282 * additional mandatory fields for root catalog: root_ctlg_location
283 * output: sqlite_path is set if catalog fetch successful
284 * @return kLoadUp2Date for root catalog that is already mounted
285 * kLoadNew for any other successful load
286 * kLoadFail on failure
287 */
288 989 LoadReturn ClientCatalogManager::LoadCatalogByHash(
289 CatalogContext *ctlg_context) {
290
1/2
✓ Branch 1 taken 989 times.
✗ Branch 2 not taken.
989 const string catalog_descr = GetCatalogDescription(ctlg_context->mountpoint(),
291
1/2
✓ Branch 2 taken 989 times.
✗ Branch 3 not taken.
1978 ctlg_context->hash());
292
1/2
✓ Branch 2 taken 989 times.
✗ Branch 3 not taken.
989 string alt_root_catalog_path = "";
293
294 // root catalog needs special handling because of alt_root_catalog_path
295
5/8
✓ Branch 1 taken 989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 789 times.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 789 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 989 times.
989 if (ctlg_context->IsRootCatalog() && fixed_alt_root_catalog_) {
296 alt_root_catalog_path = ctlg_context->hash().MakeAlternativePath();
297 }
298
299
1/2
✓ Branch 2 taken 989 times.
✗ Branch 3 not taken.
1978 const LoadReturn load_ret = FetchCatalogByHash(
300 989 ctlg_context->hash(), catalog_descr, alt_root_catalog_path,
301 ctlg_context->GetSqlitePathPtr());
302
2/2
✓ Branch 0 taken 981 times.
✓ Branch 1 taken 8 times.
989 if (load_ret == catalog::kLoadNew) {
303
2/4
✓ Branch 2 taken 981 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 981 times.
✗ Branch 6 not taken.
981 loaded_catalogs_[ctlg_context->mountpoint()] = ctlg_context->hash();
304
305
3/4
✓ Branch 1 taken 981 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 789 times.
✓ Branch 4 taken 192 times.
981 if (ctlg_context->IsRootCatalog()) {
306
2/2
✓ Branch 1 taken 577 times.
✓ Branch 2 taken 212 times.
789 if (ctlg_context->root_ctlg_location() == kCtlgLocationMounted) {
307 577 return kLoadUp2Date;
308 }
309
310 // if coming from server: update breadcrumb
311
1/2
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
212 if (ctlg_context->root_ctlg_location() == kCtlgLocationServer) {
312 // Keep a copy of the manifest, it backs the repo_metainfo xattr
313 manifest_ = new manifest::Manifest(
314
4/8
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 212 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 212 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 212 times.
✗ Branch 11 not taken.
212 *ctlg_context->manifest_ensemble()->manifest);
315
316 // Store new manifest and certificate
317 212 CacheManager::Label label;
318
1/2
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
212 label.path = repo_name_;
319 212 label.flags |= CacheManager::kLabelCertificate;
320
3/4
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 174 times.
✓ Branch 4 taken 38 times.
212 if (ctlg_context->manifest_ensemble()->cert_size > 0) {
321
1/2
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
348 fetcher_->cache_mgr()->CommitFromMem(
322
1/2
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
348 CacheManager::LabeledObject(
323 348 ctlg_context->manifest_ensemble()->manifest->certificate(),
324 label),
325
1/2
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
174 ctlg_context->manifest_ensemble()->cert_buf,
326
2/4
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 174 times.
✗ Branch 5 not taken.
174 ctlg_context->manifest_ensemble()->cert_size);
327 }
328 212 fetcher_->cache_mgr()->StoreBreadcrumb(
329
2/4
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 212 times.
✗ Branch 5 not taken.
212 *ctlg_context->manifest_ensemble()->manifest);
330 212 }
331 }
332 }
333
334 412 return load_ret;
335 989 }
336
337 /**
338 * Fetch a catalog by hash either from cache or from remote.
339 * Successful load always returns kLoadNew (independent of the location) and
340 * sets the sqlite_path variable.
341 *
342 * @param [out] sqlite_path of the catalog if successfully fetched
343 * @return kLoadNew on success
344 * kLoadNoSpace out of space, no room on the device to open the catalog
345 * kLoadFail on all other failures
346 */
347 989 LoadReturn ClientCatalogManager::FetchCatalogByHash(
348 const shash::Any &hash,
349 const string &name,
350 const std::string &alt_root_catalog_path,
351 std::string *sqlite_path) {
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 989 times.
989 assert(hash.suffix == shash::kSuffixCatalog);
353 989 CacheManager::Label label;
354
1/2
✓ Branch 1 taken 989 times.
✗ Branch 2 not taken.
989 label.path = name;
355 989 label.flags = CacheManager::kLabelCatalog;
356
2/4
✓ Branch 1 taken 989 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 989 times.
✗ Branch 5 not taken.
989 const int fd = fetcher_->Fetch(CacheManager::LabeledObject(hash, label),
357 alt_root_catalog_path);
358
2/2
✓ Branch 0 taken 981 times.
✓ Branch 1 taken 8 times.
989 if (fd >= 0) {
359
2/2
✓ Branch 0 taken 771 times.
✓ Branch 1 taken 210 times.
981 if (root_fd_ < 0) {
360 771 root_fd_ = fd;
361 }
362
363
1/2
✓ Branch 1 taken 981 times.
✗ Branch 2 not taken.
981 LogCvmfs(kLogCatalog, kLogDebug, "FetchCatalogByHash filedescriptor %d",
364 fd);
365
2/4
✓ Branch 1 taken 981 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 981 times.
✗ Branch 5 not taken.
981 *sqlite_path = "@" + StringifyInt(fd);
366 981 return kLoadNew;
367 }
368
369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (fd == -ENOSPC)
370 return kLoadNoSpace;
371
372 8 return kLoadFail;
373 989 }
374
375 76 void ClientCatalogManager::StageNestedCatalogByHash(
376 const shash::Any &hash, const PathString &mountpoint) {
377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 assert(hash.suffix == shash::kSuffixCatalog);
378
379 76 CacheManager::Label label;
380
1/2
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
76 label.path = GetCatalogDescription(mountpoint, hash);
381 76 label.flags = CacheManager::kLabelCatalog;
382
3/6
✓ Branch 2 taken 76 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 76 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 76 times.
✗ Branch 9 not taken.
76 const int fd = fetcher_->Fetch(CacheManager::LabeledObject(hash, label));
383
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (fd >= 0)
384
1/2
✓ Branch 2 taken 76 times.
✗ Branch 3 not taken.
76 fetcher_->cache_mgr()->Close(fd);
385 76 }
386
387 2 void ClientCatalogManager::UnloadCatalog(const Catalog *catalog) {
388
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 LogCvmfs(kLogCache, kLogDebug, "unloading catalog %s",
389
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 catalog->mountpoint().c_str());
390
391
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 const map<PathString, shash::Any>::iterator iter = mounted_catalogs_.find(
392
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 catalog->mountpoint());
393
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 assert(iter != mounted_catalogs_.end());
394
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 fetcher_->cache_mgr()->quota_mgr()->Unpin(iter->second);
395
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 mounted_catalogs_.erase(iter);
396 2 const catalog::Counters &counters = catalog->GetCounters();
397
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 loaded_inodes_ -= counters.GetSelfEntries();
398 2 }
399
400
401 /**
402 * Checks if the current repository revision is blacklisted. The format
403 * of the blacklist lines is '<REPO N' where REPO is the repository name,
404 * N is the revision number, and the two parts are separated by whitespace.
405 * Any revision of REPO less than N is blacklisted.
406 * Note: no extra characters are allowed after N, not even whitespace.
407 * @return true if it is blacklisted, false otherwise
408 */
409 771 bool ClientCatalogManager::IsRevisionBlacklisted() {
410 771 const uint64_t revision = GetRevision();
411
412
1/2
✓ Branch 2 taken 771 times.
✗ Branch 3 not taken.
771 LogCvmfs(kLogCache, kLogDebug,
413 "checking if %s revision %" PRIu64 " is blacklisted",
414 repo_name_.c_str(), revision);
415
416
1/2
✓ Branch 1 taken 771 times.
✗ Branch 2 not taken.
771 vector<string> blacklist = signature_mgr_->GetBlacklist();
417
2/2
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 734 times.
771 for (unsigned i = 0; i < blacklist.size(); ++i) {
418
1/2
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 std::string line = blacklist[i];
419
2/4
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
37 if (line[0] != '<')
420 continue;
421 37 unsigned idx = repo_name_.length() + 1;
422
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
37 if (line.length() <= idx)
423 continue;
424
3/10
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 37 times.
37 if ((line[idx] != ' ') && (line[idx] != '\t'))
425 continue;
426
2/4
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 37 times.
37 if (line.substr(1, idx - 1) != repo_name_)
427 continue;
428 37 ++idx;
429
5/10
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 37 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 37 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 37 times.
37 while ((line[idx] == ' ') || (line[idx] == '\t'))
430 ++idx;
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
37 if (idx >= line.length())
432 continue;
433 uint64_t rev;
434
3/6
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 37 times.
37 if (!String2Uint64Parse(line.substr(idx), &rev))
435 continue;
436
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 if (revision < rev)
437 37 return true;
438
1/3
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
37 }
439
440 734 return false;
441 771 }
442
443
444 //------------------------------------------------------------------------------
445
446
447 249 void CachedManifestEnsemble::FetchCertificate(const shash::Any &hash) {
448 249 CacheManager::Label label;
449 249 label.flags |= CacheManager::kLabelCertificate;
450
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 label.path = catalog_mgr_->repo_name();
451 uint64_t size;
452
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
249 const bool retval = cache_mgr_->Open2Mem(
453
1/2
✓ Branch 1 taken 249 times.
✗ Branch 2 not taken.
498 CacheManager::LabeledObject(hash, label), &cert_buf, &size);
454 249 cert_size = size;
455
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 247 times.
249 if (retval)
456 2 perf::Inc(catalog_mgr_->n_certificate_hits_);
457 else
458 247 perf::Inc(catalog_mgr_->n_certificate_misses_);
459 249 }
460
461 } // namespace catalog
462