Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_LOADER_H_ |
6 |
|
|
#define CVMFS_LOADER_H_ |
7 |
|
|
|
8 |
|
|
#define _FILE_OFFSET_BITS 64 |
9 |
|
|
|
10 |
|
|
#include <stdint.h> |
11 |
|
|
#include <time.h> |
12 |
|
|
|
13 |
|
|
#include <cstring> |
14 |
|
|
#include <string> |
15 |
|
|
#include <vector> |
16 |
|
|
|
17 |
|
|
#include "duplex_fuse.h" |
18 |
|
|
|
19 |
|
|
namespace loader { |
20 |
|
|
|
21 |
|
|
extern std::string *usyslog_path_; |
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* Possible failures when booting/mounting cvmfs. Remember to add a constant |
25 |
|
|
* to libcvmfs.h and libcvmfs_legacy.cc when a constant to this enum is added. |
26 |
|
|
*/ |
27 |
|
|
enum Failures { |
28 |
|
|
kFailOk = 0, |
29 |
|
|
kFailUnknown, |
30 |
|
|
kFailOptions, |
31 |
|
|
kFailPermission, |
32 |
|
|
kFailMount, |
33 |
|
|
kFailLoaderTalk, |
34 |
|
|
kFailFuseLoop, |
35 |
|
|
kFailLoadLibrary, |
36 |
|
|
kFailIncompatibleVersions, // TODO(jblomer) |
37 |
|
|
kFailCacheDir, |
38 |
|
|
kFailPeers, |
39 |
|
|
kFailNfsMaps, |
40 |
|
|
kFailQuota, |
41 |
|
|
kFailMonitor, |
42 |
|
|
kFailTalk, |
43 |
|
|
kFailSignature, |
44 |
|
|
kFailCatalog, |
45 |
|
|
kFailMaintenanceMode, |
46 |
|
|
kFailSaveState, |
47 |
|
|
kFailRestoreState, |
48 |
|
|
kFailOtherMount, |
49 |
|
|
kFailDoubleMount, |
50 |
|
|
kFailHistory, |
51 |
|
|
kFailWpad, |
52 |
|
|
kFailLockWorkspace, |
53 |
|
|
kFailRevisionBlacklisted, |
54 |
|
|
|
55 |
|
|
kFailNumEntries |
56 |
|
|
}; |
57 |
|
|
|
58 |
|
✗ |
inline const char *Code2Ascii(const Failures error) { |
59 |
|
|
const char *texts[kFailNumEntries + 1]; |
60 |
|
✗ |
texts[0] = "OK"; |
61 |
|
✗ |
texts[1] = "unknown error"; |
62 |
|
✗ |
texts[2] = "illegal options"; |
63 |
|
✗ |
texts[3] = "permission denied"; |
64 |
|
✗ |
texts[4] = "failed to mount"; |
65 |
|
✗ |
texts[5] = "unable to init loader talk socket"; |
66 |
|
✗ |
texts[6] = "cannot run FUSE event loop"; |
67 |
|
✗ |
texts[7] = "failed to load shared library"; |
68 |
|
✗ |
texts[8] = "incompatible library version"; |
69 |
|
✗ |
texts[9] = "cache directory/plugin problem"; |
70 |
|
✗ |
texts[10] = "peering problem"; |
71 |
|
✗ |
texts[11] = "NFS maps init failure"; |
72 |
|
✗ |
texts[12] = "quota init failure"; |
73 |
|
✗ |
texts[13] = "watchdog failure"; |
74 |
|
✗ |
texts[14] = "talk socket failure"; |
75 |
|
✗ |
texts[15] = "signature verification failure"; |
76 |
|
✗ |
texts[16] = "file catalog failure"; |
77 |
|
✗ |
texts[17] = "maintenance mode"; |
78 |
|
✗ |
texts[18] = "state saving failure"; |
79 |
|
✗ |
texts[19] = "state restore failure"; |
80 |
|
✗ |
texts[20] = "already mounted"; |
81 |
|
✗ |
texts[21] = "double mount"; |
82 |
|
✗ |
texts[22] = "history init failure"; |
83 |
|
✗ |
texts[23] = "proxy auto-discovery failed"; |
84 |
|
✗ |
texts[24] = "workspace already locked"; |
85 |
|
✗ |
texts[25] = "revision blacklisted"; |
86 |
|
✗ |
texts[26] = "no text"; |
87 |
|
✗ |
return texts[error]; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
enum StateId { |
92 |
|
|
kStateUnknown = 0, |
93 |
|
|
kStateOpenDirs, // >= 2.1.4 |
94 |
|
|
kStateOpenChunks, // >= 2.1.4, used as of 2.1.15 |
95 |
|
|
kStateGlueBuffer, // >= 2.1.9 |
96 |
|
|
kStateInodeGeneration, // >= 2.1.9 |
97 |
|
|
kStateOpenFilesCounter, // >= 2.1.9 |
98 |
|
|
kStateGlueBufferV2, // >= 2.1.10 |
99 |
|
|
kStateGlueBufferV3, // >= 2.1.15 |
100 |
|
|
kStateGlueBufferV4, // >= 2.1.20 |
101 |
|
|
kStateOpenChunksV2, // >= 2.1.20 |
102 |
|
|
kStateOpenChunksV3, // >= 2.2.0 |
103 |
|
|
kStateOpenChunksV4, // >= 2.2.3 |
104 |
|
|
kStateOpenFiles, // >= 2.4 |
105 |
|
|
kStateDentryTracker, // >= 2.7 (renamed from kStateNentryTracker in 2.10) |
106 |
|
|
kStatePageCacheTracker, // >= 2.10 |
107 |
|
|
kStateFuse // >= 2.11 |
108 |
|
|
|
109 |
|
|
// Note: kStateOpenFilesXXX was renamed to kStateOpenChunksXXX as of 2.4 |
110 |
|
|
}; |
111 |
|
|
|
112 |
|
|
|
113 |
|
|
struct SavedState { |
114 |
|
✗ |
SavedState() { |
115 |
|
✗ |
version = 1; |
116 |
|
✗ |
size = sizeof(SavedState); |
117 |
|
✗ |
state_id = kStateUnknown; |
118 |
|
✗ |
state = NULL; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
uint32_t version; |
122 |
|
|
uint32_t size; |
123 |
|
|
StateId state_id; |
124 |
|
|
void *state; |
125 |
|
|
}; |
126 |
|
|
typedef std::vector<SavedState *> StateList; |
127 |
|
|
|
128 |
|
|
|
129 |
|
|
struct LoadEvent { |
130 |
|
✗ |
LoadEvent() { |
131 |
|
✗ |
version = 1; |
132 |
|
✗ |
size = sizeof(LoadEvent); |
133 |
|
✗ |
timestamp = 0; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
uint32_t version; |
137 |
|
|
uint32_t size; |
138 |
|
|
time_t timestamp; |
139 |
|
|
std::string so_version; |
140 |
|
|
}; |
141 |
|
|
typedef std::vector<LoadEvent *> EventList; |
142 |
|
|
|
143 |
|
|
|
144 |
|
|
/** |
145 |
|
|
* This contains the public interface of the cvmfs loader. |
146 |
|
|
* Whenever something changes, change the version number. |
147 |
|
|
* |
148 |
|
|
* Note: Do not forget to check the version of LoaderExports in cvmfs.cc when |
149 |
|
|
* using fields that were not present in version 1 |
150 |
|
|
* |
151 |
|
|
* CernVM-FS 2.1.8 --> Version 2 |
152 |
|
|
* CernVM-FS 2.2.0 --> Version 3 |
153 |
|
|
* CernVM-FS 2.4.0 --> Version 4 |
154 |
|
|
* CernVM-FS 2.7.0 --> Version 4, fuse_channel --> fuse_channel_or_session |
155 |
|
|
* CernVM-FS 2.8.2 --> Version 5, add device_id |
156 |
|
|
*/ |
157 |
|
|
struct LoaderExports { |
158 |
|
✗ |
LoaderExports() : |
159 |
|
✗ |
version(5), |
160 |
|
✗ |
size(sizeof(LoaderExports)), |
161 |
|
✗ |
boot_time(0), |
162 |
|
✗ |
foreground(false), |
163 |
|
✗ |
disable_watchdog(false), |
164 |
|
✗ |
simple_options_parsing(false), |
165 |
|
✗ |
fuse_channel_or_session(NULL) |
166 |
|
✗ |
{ } |
167 |
|
|
|
168 |
|
✗ |
~LoaderExports() { |
169 |
|
✗ |
for (unsigned i = 0; i < history.size(); ++i) |
170 |
|
✗ |
delete history[i]; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
uint32_t version; |
174 |
|
|
uint32_t size; |
175 |
|
|
time_t boot_time; |
176 |
|
|
std::string loader_version; |
177 |
|
|
bool foreground; |
178 |
|
|
std::string repository_name; |
179 |
|
|
std::string mount_point; |
180 |
|
|
std::string config_files; |
181 |
|
|
std::string program_name; |
182 |
|
|
EventList history; |
183 |
|
|
StateList saved_states; |
184 |
|
|
|
185 |
|
|
// added with CernVM-FS 2.1.8 (LoaderExports Version: 2) |
186 |
|
|
bool disable_watchdog; |
187 |
|
|
|
188 |
|
|
// added with CernVM-FS 2.2.0 (LoaderExports Version: 3) |
189 |
|
|
bool simple_options_parsing; |
190 |
|
|
|
191 |
|
|
// added with CernVM-FS 2.4.0 (LoaderExports Version: 4) |
192 |
|
|
// As of CernVM-FS 2.7, this has been rebranded from |
193 |
|
|
// struct fuse_chan **fuse_channel to |
194 |
|
|
// void **fuse_channel_or_session |
195 |
|
|
// in order to work with both libfuse2 and libfuse3 |
196 |
|
|
void **fuse_channel_or_session; |
197 |
|
|
|
198 |
|
|
// Linux only, stores the major:minor internal mountpoint identifier |
199 |
|
|
// The identifier is read just after mount from /proc/self/mountinfo |
200 |
|
|
// If it cannot be determined (e.g. on macOS), device_id is "0:0". |
201 |
|
|
std::string device_id; |
202 |
|
|
}; |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
/** |
206 |
|
|
* This contains the public interface of the cvmfs fuse module. |
207 |
|
|
* Whenever something changes, change the version number. |
208 |
|
|
* A global CvmfsExports struct is looked up by the loader via dlsym. |
209 |
|
|
* |
210 |
|
|
* Note: as of cvmfs version 2.8, we set cvmfs_operations.forget_multi on new |
211 |
|
|
* enough fuse |
212 |
|
|
*/ |
213 |
|
|
struct CvmfsExports { |
214 |
|
✗ |
CvmfsExports() { |
215 |
|
✗ |
version = 1; |
216 |
|
✗ |
size = sizeof(CvmfsExports); |
217 |
|
✗ |
fnAltProcessFlavor = NULL; |
218 |
|
✗ |
fnInit = NULL; |
219 |
|
✗ |
fnSpawn = NULL; |
220 |
|
✗ |
fnFini = NULL; |
221 |
|
✗ |
fnGetErrorMsg = NULL; |
222 |
|
✗ |
fnMaintenanceMode = NULL; |
223 |
|
✗ |
fnSaveState = NULL; |
224 |
|
✗ |
fnRestoreState = NULL; |
225 |
|
✗ |
fnFreeSavedState = NULL; |
226 |
|
✗ |
memset(&cvmfs_operations, 0, sizeof(cvmfs_operations)); |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
uint32_t version; |
230 |
|
|
uint32_t size; |
231 |
|
|
std::string so_version; |
232 |
|
|
|
233 |
|
|
int (*fnAltProcessFlavor)(int argc, char **argv); |
234 |
|
|
int (*fnInit)(const LoaderExports *loader_exports); |
235 |
|
|
void (*fnSpawn)(); |
236 |
|
|
void (*fnFini)(); |
237 |
|
|
std::string (*fnGetErrorMsg)(); |
238 |
|
|
bool (*fnMaintenanceMode)(const int fd_progress); |
239 |
|
|
bool (*fnSaveState)(const int fd_progress, StateList *saved_states); |
240 |
|
|
bool (*fnRestoreState)(const int fd_progress, const StateList &saved_states); |
241 |
|
|
void (*fnFreeSavedState)(const int fd_progress, |
242 |
|
|
const StateList &saved_states); |
243 |
|
|
struct fuse_lowlevel_ops cvmfs_operations; |
244 |
|
|
}; |
245 |
|
|
|
246 |
|
|
enum ReloadMode { |
247 |
|
|
kReloadNoDebug = 0, |
248 |
|
|
kReloadDebug, |
249 |
|
|
kReloadLegacy |
250 |
|
|
}; |
251 |
|
|
|
252 |
|
|
Failures Reload(const int fd_progress, const bool stop_and_go, |
253 |
|
|
const ReloadMode reload_mode = kReloadLegacy); |
254 |
|
|
|
255 |
|
|
} // namespace loader |
256 |
|
|
|
257 |
|
|
#endif // CVMFS_LOADER_H_ |
258 |
|
|
|