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 FUSE_USE_VERSION 26 |
9 |
|
|
#define _FILE_OFFSET_BITS 64 |
10 |
|
|
|
11 |
|
|
#include <fuse/fuse_lowlevel.h> |
12 |
|
|
#include <stdint.h> |
13 |
|
|
#include <time.h> |
14 |
|
|
|
15 |
|
|
#include <cstring> |
16 |
|
|
#include <string> |
17 |
|
|
#include <vector> |
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 |
|
|
|
106 |
|
|
// Note: kStateOpenFilesXXX was renamed to kStateOpenChunksXXX as of 2.4 |
107 |
|
|
}; |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
struct SavedState { |
111 |
|
|
SavedState() { |
112 |
|
|
version = 1; |
113 |
|
|
size = sizeof(SavedState); |
114 |
|
|
state_id = kStateUnknown; |
115 |
|
|
state = NULL; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
uint32_t version; |
119 |
|
|
uint32_t size; |
120 |
|
|
StateId state_id; |
121 |
|
|
void *state; |
122 |
|
|
}; |
123 |
|
|
typedef std::vector<SavedState *> StateList; |
124 |
|
|
|
125 |
|
|
|
126 |
|
|
struct LoadEvent { |
127 |
|
|
LoadEvent() { |
128 |
|
|
version = 1; |
129 |
|
|
size = sizeof(LoadEvent); |
130 |
|
|
timestamp = 0; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
uint32_t version; |
134 |
|
|
uint32_t size; |
135 |
|
|
time_t timestamp; |
136 |
|
|
std::string so_version; |
137 |
|
|
}; |
138 |
|
|
typedef std::vector<LoadEvent *> EventList; |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
/** |
142 |
|
|
* This contains the public interface of the cvmfs loader. |
143 |
|
|
* Whenever something changes, change the version number. |
144 |
|
|
* |
145 |
|
|
* Note: Do not forget to check the version of LoaderExports in cvmfs.cc when |
146 |
|
|
* using fields that were not present in version 1 |
147 |
|
|
* |
148 |
|
|
* CernVM-FS 2.1.8 --> Version 2 |
149 |
|
|
* CernVM-FS 2.2.0 --> Version 3 |
150 |
|
|
* CernVM-FS 2.4.0 --> Version 4 |
151 |
|
|
*/ |
152 |
|
|
struct LoaderExports { |
153 |
|
|
LoaderExports() : |
154 |
|
|
version(4), |
155 |
|
|
size(sizeof(LoaderExports)), |
156 |
|
|
boot_time(0), |
157 |
|
|
foreground(false), |
158 |
|
|
disable_watchdog(false), |
159 |
|
|
simple_options_parsing(false), |
160 |
|
|
fuse_channel(NULL) |
161 |
|
|
{ } |
162 |
|
|
|
163 |
|
|
~LoaderExports() { |
164 |
|
|
for (unsigned i = 0; i < history.size(); ++i) |
165 |
|
|
delete history[i]; |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
uint32_t version; |
169 |
|
|
uint32_t size; |
170 |
|
|
time_t boot_time; |
171 |
|
|
std::string loader_version; |
172 |
|
|
bool foreground; |
173 |
|
|
std::string repository_name; |
174 |
|
|
std::string mount_point; |
175 |
|
|
std::string config_files; |
176 |
|
|
std::string program_name; |
177 |
|
|
EventList history; |
178 |
|
|
StateList saved_states; |
179 |
|
|
|
180 |
|
|
// added with CernVM-FS 2.1.8 (LoaderExports Version: 2) |
181 |
|
|
bool disable_watchdog; |
182 |
|
|
|
183 |
|
|
// added with CernVM-FS 2.2.0 (LoaderExports Version: 3) |
184 |
|
|
bool simple_options_parsing; |
185 |
|
|
|
186 |
|
|
// added with CernVM-FS 2.4.0 (LoaderExports Version: 4) |
187 |
|
|
struct fuse_chan **fuse_channel; |
188 |
|
|
}; |
189 |
|
|
|
190 |
|
|
|
191 |
|
|
/** |
192 |
|
|
* This contains the public interface of the cvmfs fuse module. |
193 |
|
|
* Whenever something changes, change the version number. |
194 |
|
|
* A global CvmfsExports struct is looked up by the loader via dlsym. |
195 |
|
|
*/ |
196 |
|
|
struct CvmfsExports { |
197 |
|
|
CvmfsExports() { |
198 |
|
|
version = 1; |
199 |
|
|
size = sizeof(CvmfsExports); |
200 |
|
|
fnAltProcessFlavor = NULL; |
201 |
|
|
fnInit = NULL; |
202 |
|
|
fnSpawn = NULL; |
203 |
|
|
fnFini = NULL; |
204 |
|
|
fnGetErrorMsg = NULL; |
205 |
|
|
fnMaintenanceMode = NULL; |
206 |
|
|
fnSaveState = NULL; |
207 |
|
|
fnRestoreState = NULL; |
208 |
|
|
fnFreeSavedState = NULL; |
209 |
|
|
memset(&cvmfs_operations, 0, sizeof(cvmfs_operations)); |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
uint32_t version; |
213 |
|
|
uint32_t size; |
214 |
|
|
std::string so_version; |
215 |
|
|
|
216 |
|
|
int (*fnAltProcessFlavor)(int argc, char **argv); |
217 |
|
|
int (*fnInit)(const LoaderExports *loader_exports); |
218 |
|
|
void (*fnSpawn)(); |
219 |
|
|
void (*fnFini)(); |
220 |
|
|
std::string (*fnGetErrorMsg)(); |
221 |
|
|
bool (*fnMaintenanceMode)(const int fd_progress); |
222 |
|
|
bool (*fnSaveState)(const int fd_progress, StateList *saved_states); |
223 |
|
|
bool (*fnRestoreState)(const int fd_progress, const StateList &saved_states); |
224 |
|
|
void (*fnFreeSavedState)(const int fd_progress, |
225 |
|
|
const StateList &saved_states); |
226 |
|
|
struct fuse_lowlevel_ops cvmfs_operations; |
227 |
|
|
}; |
228 |
|
|
|
229 |
|
|
Failures Reload(const int fd_progress, const bool stop_and_go); |
230 |
|
|
|
231 |
|
|
} // namespace loader |
232 |
|
|
|
233 |
|
|
#endif // CVMFS_LOADER_H_ |