GCC Code Coverage Report


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