GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/catalog_mgr_client.h
Date: 2025-06-29 02:35:41
Exec Total Coverage
Lines: 3 8 37.5%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_CATALOG_MGR_CLIENT_H_
6 #define CVMFS_CATALOG_MGR_CLIENT_H_
7
8 #include <inttypes.h>
9
10 #include <map>
11 #include <string>
12
13 #include "backoff.h"
14 #include "catalog_mgr.h"
15 #include "crypto/hash.h"
16 #include "gtest/gtest_prod.h"
17 #include "manifest_fetch.h"
18 #include "shortstring.h"
19
20 class CacheManager;
21 namespace cvmfs {
22 class Fetcher;
23 }
24 class MountPoint;
25 namespace perf {
26 class Counter;
27 class Statistics;
28 } // namespace perf
29 namespace signature {
30 class SignatureManager;
31 }
32
33 namespace catalog {
34
35 /**
36 * A catalog manager that uses a Fetcher to get file catalgs in the form of
37 * (virtual) file descriptors from a cache manager. Sqlite has a path based
38 * interface. This catalog manager returns @<FILE DESCRIPTOR> as a path and
39 * thus requires a sqlite vfs that supports this syntax, such as the cvmfs
40 * default vfs for clients.
41 *
42 * This class uses the Fetcher in order to get access to the download manager
43 * and the cache manager, too. It requires a download manager and a signature
44 * manager as it calls manifest::Fetch in order to get the manifest of new and
45 * updated root catalogs. It requires the cache manager to get access to the
46 * Unpin() method of the corresponding quota manager; loaded catalogs need to
47 * be unpinned when the class is destructed.
48 */
49 class ClientCatalogManager : public AbstractCatalogManager<Catalog> {
50 FRIEND_TEST(T_CatalogManagerClient, MountLatest);
51 FRIEND_TEST(T_CatalogManagerClient, LoadByHash);
52 FRIEND_TEST(T_CatalogManagerClient, LoadByHashNetworkFailure);
53 FRIEND_TEST(T_CatalogManagerClient, LoadRootCatalog);
54
55 // Maintains certificate hit/miss counters
56 friend class CachedManifestEnsemble;
57
58 public:
59 explicit ClientCatalogManager(MountPoint *mountpoint);
60 virtual ~ClientCatalogManager();
61
62 bool InitFixed(const shash::Any &root_hash, bool alternative_path);
63
64 shash::Any GetRootHash();
65 std::string GetCatalogDescription(const PathString &mountpoint,
66 const shash::Any &hash);
67
68 bool IsRevisionBlacklisted();
69
70 bool offline_mode() const { return offline_mode_; }
71 uint64_t all_inodes() const { return all_inodes_; }
72 uint64_t loaded_inodes() const { return loaded_inodes_; }
73 132 std::string repo_name() const { return repo_name_; }
74 manifest::Manifest *manifest() const { return manifest_.weak_ref(); }
75 int root_fd() const { return root_fd_; }
76
77 protected:
78 virtual LoadReturn GetNewRootCatalogContext(CatalogContext *result);
79 virtual LoadReturn LoadCatalogByHash(CatalogContext *ctlg_context);
80 virtual void StageNestedCatalogByHash(const shash::Any &hash,
81 const PathString &mountpoint);
82 void UnloadCatalog(const catalog::Catalog *catalog);
83 catalog::Catalog *CreateCatalog(const PathString &mountpoint,
84 const shash::Any &catalog_hash,
85 catalog::Catalog *parent_catalog);
86 void ActivateCatalog(catalog::Catalog *catalog);
87
88 private:
89 LoadReturn FetchCatalogByHash(const shash::Any &hash,
90 const std::string &name,
91 const std::string &alt_catalog_path,
92 std::string *catalog_path);
93
94 /**
95 * Required for unpinning
96 */
97 std::map<PathString, shash::Any> loaded_catalogs_;
98 std::map<PathString, shash::Any> mounted_catalogs_;
99
100 UniquePtr<manifest::Manifest> manifest_;
101
102 std::string repo_name_;
103 cvmfs::Fetcher *fetcher_;
104 signature::SignatureManager *signature_mgr_;
105 std::string workspace_;
106 bool offline_mode_; /**< cached copy used because there is no network */
107 uint64_t all_inodes_;
108 uint64_t loaded_inodes_;
109 shash::Any fixed_root_catalog_; /**< fixed root hash */
110 bool fixed_alt_root_catalog_; /**< fixed root hash but alternative url */
111 BackoffThrottle backoff_throttle_;
112 perf::Counter *n_certificate_hits_;
113 perf::Counter *n_certificate_misses_;
114
115 /**
116 * File descriptor of first loaded catalog; used for mapping the root catalog
117 * file descriptor when restoring the cache manager after a fuse module reload
118 */
119 int root_fd_;
120 };
121
122
123 /**
124 * Tries to fetch the certificate from cache
125 */
126 class CachedManifestEnsemble : public manifest::ManifestEnsemble {
127 public:
128 259 CachedManifestEnsemble(CacheManager *cache_mgr,
129 ClientCatalogManager *catalog_mgr)
130 259 : cache_mgr_(cache_mgr), catalog_mgr_(catalog_mgr) { }
131 void FetchCertificate(const shash::Any &hash);
132
133 private:
134 CacheManager *cache_mgr_;
135 ClientCatalogManager *catalog_mgr_;
136 };
137
138 } // namespace catalog
139
140 #endif // CVMFS_CATALOG_MGR_CLIENT_H_
141