1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
* |
4 |
|
|
* This is the internal implementation of libcvmfs, not to be exposed to the |
5 |
|
|
* code using the library. |
6 |
|
|
* |
7 |
|
|
* Defines LibGlobals and LibContext classes that wrap around a FileSystem |
8 |
|
|
* and a MountPoint. The libcvmfs.cc implementation of the libcvmfs interface |
9 |
|
|
* uses LibGlobals for library initialization and deinitialization. It uses |
10 |
|
|
* LibContext objects for all the file system heavy lifting. |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
#ifndef CVMFS_LIBCVMFS_INT_H_ |
14 |
|
|
#define CVMFS_LIBCVMFS_INT_H_ |
15 |
|
|
|
16 |
|
|
#include <syslog.h> |
17 |
|
|
#include <time.h> |
18 |
|
|
#include <unistd.h> |
19 |
|
|
|
20 |
|
|
#include <string> |
21 |
|
|
#include <vector> |
22 |
|
|
|
23 |
|
|
#include "backoff.h" |
24 |
|
|
#include "catalog_mgr.h" |
25 |
|
|
#include "file_chunk.h" |
26 |
|
|
#include "loader.h" |
27 |
|
|
#include "lru.h" |
28 |
|
|
#include "mountpoint.h" |
29 |
|
|
#include "options.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
class CacheManager; |
33 |
|
|
namespace catalog { |
34 |
|
|
class ClientCatalogManager; |
35 |
|
|
} |
36 |
|
|
namespace signature { |
37 |
|
|
class SignatureManager; |
38 |
|
|
} |
39 |
|
|
namespace download { |
40 |
|
|
class DownloadManager; |
41 |
|
|
} |
42 |
|
|
namespace perf { |
43 |
|
|
class Statistics; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
namespace cvmfs { |
47 |
|
|
extern pid_t pid_; |
48 |
|
|
extern std::string *repository_name_; |
49 |
|
|
extern bool foreground_; |
50 |
|
|
class Fetcher; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/** |
55 |
|
|
* A singleton managing the cvmfs resources for all attached repositories. A |
56 |
|
|
* thin wrapper around the FileSystem object that does most of the heavy work. |
57 |
|
|
*/ |
58 |
|
|
class LibGlobals : SingleCopy { |
59 |
|
|
public: |
60 |
|
|
static loader::Failures Initialize(OptionsManager *options_mgr); |
61 |
|
|
static void CleanupInstance(); |
62 |
|
|
static LibGlobals* GetInstance(); |
63 |
|
|
|
64 |
|
32 |
FileSystem *file_system() { return file_system_; } |
65 |
|
12 |
void set_options_mgr(OptionsManager *value) { options_mgr_ = value; } |
66 |
|
|
|
67 |
|
|
private: |
68 |
|
|
LibGlobals(); |
69 |
|
|
~LibGlobals(); |
70 |
|
|
static void CallbackLibcryptoLock(int mode, int type, |
71 |
|
|
const char *file, int line); |
72 |
|
|
// unsigned long type required by libcrypto (openssl) |
73 |
|
|
static unsigned long CallbackLibcryptoThreadId(); // NOLINT |
74 |
|
|
|
75 |
|
|
static LibGlobals *instance_; |
76 |
|
|
|
77 |
|
|
/** |
78 |
|
|
* Only non-NULL if cvmfs_init is used for initialization. In this case, the |
79 |
|
|
* options manager needs to be cleaned up by cvmfs_fini. |
80 |
|
|
*/ |
81 |
|
|
OptionsManager *options_mgr_; |
82 |
|
|
FileSystem *file_system_; |
83 |
|
|
|
84 |
|
|
pthread_mutex_t *libcrypto_locks_; |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
/** |
89 |
|
|
* Encapsulates a single attached repository. It uses a MountPoint object for |
90 |
|
|
* creating the state of all the necessary manager objects. On top of the |
91 |
|
|
* managers it implements file system operations (read, list, ...). |
92 |
|
|
*/ |
93 |
|
|
class LibContext : SingleCopy { |
94 |
|
|
public: |
95 |
|
|
static LibContext *Create(const std::string &fqrn, |
96 |
|
|
OptionsManager *options_mgr); |
97 |
|
|
~LibContext(); |
98 |
|
|
|
99 |
|
|
void EnableMultiThreaded(); |
100 |
|
|
int GetAttr(const char *c_path, struct stat *info); |
101 |
|
|
int Readlink(const char *path, char *buf, size_t size); |
102 |
|
|
int ListDirectory(const char *path, |
103 |
|
|
char ***buf, |
104 |
|
|
size_t *listlen, |
105 |
|
|
size_t *buflen, |
106 |
|
|
bool self_reference); |
107 |
|
|
|
108 |
|
|
int Open(const char *c_path); |
109 |
|
|
int64_t Pread(int fd, void *buf, uint64_t size, uint64_t off); |
110 |
|
|
int Close(int fd); |
111 |
|
|
|
112 |
|
|
int GetExtAttr(const char *c_path, struct cvmfs_attr *info); |
113 |
|
|
int GetNestedCatalogAttr(const char *c_path, struct cvmfs_nc_attr *nc_attr); |
114 |
|
|
int ListNestedCatalogs(const char *path, char ***buf, size_t *buflen); |
115 |
|
|
|
116 |
|
11 |
MountPoint *mount_point() { return mount_point_; } |
117 |
|
|
void set_options_mgr(OptionsManager *value) { options_mgr_ = value; } |
118 |
|
|
|
119 |
|
|
private: |
120 |
|
|
/** |
121 |
|
|
* File descriptors of chunked files have bit 30 set. |
122 |
|
|
*/ |
123 |
|
|
static const int kFdChunked = 1 << 30; |
124 |
|
|
/** |
125 |
|
|
* use static method Create() for construction |
126 |
|
|
*/ |
127 |
|
|
LibContext(); |
128 |
|
23 |
FileSystem *file_system() { return LibGlobals::GetInstance()->file_system(); } |
129 |
|
|
|
130 |
|
|
void AppendStringToList(char const *str, |
131 |
|
|
char ***buf, |
132 |
|
|
size_t *listlen, |
133 |
|
|
size_t *buflen); |
134 |
|
|
bool GetDirentForPath(const PathString &path, |
135 |
|
|
catalog::DirectoryEntry *dirent); |
136 |
|
|
void CvmfsAttrFromDirent(const catalog::DirectoryEntry dirent, |
137 |
|
|
struct cvmfs_attr *attr); |
138 |
|
|
|
139 |
|
|
/** |
140 |
|
|
* Only non-NULL if cvmfs_attache_repo is used for initialization. In this |
141 |
|
|
* case, the options manager needs to be cleaned up by cvmfs_fini. |
142 |
|
|
*/ |
143 |
|
|
OptionsManager *options_mgr_; |
144 |
|
|
MountPoint *mount_point_; |
145 |
|
|
}; |
146 |
|
|
|
147 |
|
|
#endif // CVMFS_LIBCVMFS_INT_H_ |