-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdFileCacheConfiguration.cc
312 lines (269 loc) · 9.58 KB
/
XrdFileCacheConfiguration.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#include "XrdFileCache.hh"
#include "XrdOss/XrdOss.hh"
#include "XrdOss/XrdOssCache.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucPinLoader.hh"
#include "XrdOuc/XrdOuca2x.hh"
#include "XrdOfs/XrdOfsConfigPI.hh"
#include "XrdVersion.hh"
#include <fcntl.h>
using namespace XrdFileCache;
XrdVERSIONINFO(XrdOucGetCache2, XrdFileCache);
/* Function: xdlib
Purpose: To parse the directive: decisionlib <path> [<parms>]
<path> the path of the decision library to be used.
<parms> optional parameters to be passed.
Output: true upon success or false upon failure.
*/
bool Cache::xdlib(XrdOucStream &Config)
{
const char* val;
std::string libp;
if (!(val = Config.GetWord()) || !val[0])
{
clLog()->Info(XrdCl::AppMsg, " Cache::Config() decisionlib not specified; always caching files");
return true;
}
else
{
libp = val;
}
const char* params;
params = (val[0]) ? Config.GetWord() : 0;
XrdOucPinLoader* myLib = new XrdOucPinLoader(&m_log, 0, "decisionlib",
libp.c_str());
Decision *(*ep)(XrdSysError&);
ep = (Decision *(*)(XrdSysError&))myLib->Resolve("XrdFileCacheGetDecision");
if (!ep) {myLib->Unload(true); return false;}
Decision * d = ep(m_log);
if (!d)
{
clLog()->Error(XrdCl::AppMsg, "Cache::Config() decisionlib was not able to create a decision object");
return false;
}
if (params)
d->ConfigDecision(params);
m_decisionpoints.push_back(d);
clLog()->Info(XrdCl::AppMsg, "Cache::Config() successfully created decision lib from %s", libp.c_str());
return true;
}
//______________________________________________________________________________
bool Cache::Config(XrdSysLogger *logger, const char *config_filename, const char *parameters)
{
m_log.logger(logger);
const char * cache_env;
if (!(cache_env = getenv("XRDPOSIX_CACHE")) || !*cache_env)
XrdOucEnv::Export("XRDPOSIX_CACHE", "mode=s&optwr=0");
XrdOucEnv myEnv;
XrdOucStream Config(&m_log, getenv("XRDINSTANCE"), &myEnv, "=====> ");
if (!config_filename || !*config_filename)
{
clLog()->Warning(XrdCl::AppMsg, "Cache::Config() configuration file not specified.");
return false;
}
int fd;
if ( (fd = open(config_filename, O_RDONLY, 0)) < 0)
{
clLog()->Error(XrdCl::AppMsg, "Cache::Config() can't open configuration file %s", config_filename);
return false;
}
Config.Attach(fd);
// Obtain plugin configurator
XrdOfsConfigPI *ofsCfg = XrdOfsConfigPI::New(config_filename,&Config,&m_log,
&XrdVERSIONINFOVAR(XrdOucGetCache2));
if (!ofsCfg) return false;
if (ofsCfg->Load(XrdOfsConfigPI::theOssLib)) {
ofsCfg->Plugin(m_output_fs);
XrdOssCache_FS* ocfs = XrdOssCache::Find("public");
ocfs->Add(m_configuration.m_cache_dir.c_str());
}
else
{
clLog()->Error(XrdCl::AppMsg, "Cache::Config() Unable to create an OSS object");
m_output_fs = 0;
return false;
}
// Actual parsing of the config file.
bool retval = true;
char *var;
while((var = Config.GetMyFirstWord()))
{
if (!strcmp(var,"pfc.osslib"))
{
ofsCfg->Parse(XrdOfsConfigPI::theOssLib);
}
else if (!strcmp(var,"pfc.decisionlib"))
{
xdlib(Config);
}
else if (!strncmp(var,"pfc.", 4))
{
retval = ConfigParameters(std::string(var+4), Config);
}
if (!retval)
{
retval = false;
clLog()->Error(XrdCl::AppMsg, "Cache::Config() error in parsing");
break;
}
}
Config.Close();
// sets default value for disk usage
if (m_configuration.m_diskUsageLWM < 0 || m_configuration.m_diskUsageHWM < 0)
{
XrdOssVSInfo sP;
if (m_output_fs->StatVS(&sP, "public", 1) >= 0) {
m_configuration.m_diskUsageLWM = static_cast<long long>(0.90 * sP.Total + 0.5);
m_configuration.m_diskUsageHWM = static_cast<long long>(0.95 * sP.Total + 0.5);
clLog()->Debug(XrdCl::AppMsg, "Default disk usage [%lld, %lld]", m_configuration.m_diskUsageLWM, m_configuration.m_diskUsageHWM);
}
}
// get number of available RAM blocks after process configuration
m_configuration.m_NRamBuffers = static_cast<int>(m_configuration.m_RamAbsAvailable/ m_configuration.m_bufferSize);
if (retval)
{
int loff = 0;
char buff[2048];
loff = snprintf(buff, sizeof(buff), "result\n"
"\tpfc.blocksize %lld\n"
"\tpfc.prefetch %d\n"
"\tpfc.nramblocks %d\n\n",
m_configuration.m_bufferSize,
m_configuration.m_prefetch, // AMT not sure what parsing should be
m_configuration.m_NRamBuffers );
if (m_configuration.m_hdfsmode)
{
char buff2[512];
snprintf(buff2, sizeof(buff2), "\tpfc.hdfsmode hdfsbsize %lld\n", m_configuration.m_hdfsbsize);
loff += snprintf(&buff[loff], strlen(buff2), "%s", buff2);
}
char unameBuff[256];
if (m_configuration.m_username.empty()) {
XrdOucUtils::UserName(getuid(), unameBuff, sizeof(unameBuff));
m_configuration.m_username = unameBuff;
}
else {
snprintf(unameBuff, sizeof(unameBuff), "\tpfc.user %s \n", m_configuration.m_username.c_str());
loff += snprintf(&buff[loff], strlen(unameBuff), "%s", unameBuff);
}
m_log.Emsg("Config", buff);
}
m_log.Emsg("Config", "Configuration = ", retval ? "Success" : "Fail");
if (ofsCfg) delete ofsCfg;
return retval;
}
//______________________________________________________________________________
bool Cache::ConfigParameters(std::string part, XrdOucStream& config )
{
printf("part %s \n", part.c_str());
XrdSysError err(0, "");
if ( part == "user" )
{
m_configuration.m_username = config.GetWord();
}
else if ( part == "cachedir" )
{
m_configuration.m_cache_dir = config.GetWord();
}
else if ( part == "diskusage" )
{
std::string minV = config.GetWord();
std::string maxV = config.GetWord();
if (!minV.empty() && !maxV.empty()) {
XrdOssVSInfo sP;
if (m_output_fs->StatVS(&sP, "public", 1) >= 0)
{
if (::isalpha(*(minV.rbegin())) && ::isalpha(*(minV.rbegin()))) {
if ( XrdOuca2x::a2sz(m_log, "Error getting disk usage low watermark", minV.c_str(), &m_configuration.m_diskUsageLWM, 0, sP.Total)
|| XrdOuca2x::a2sz(m_log, "Error getting disk usage high watermark", maxV.c_str(), &m_configuration.m_diskUsageHWM, 0, sP.Total))
{
return false;
}
}
else
{
char* eP;
errno = 0;
float lwmf = strtod(minV.c_str(), &eP);
if (errno || eP == minV.c_str()) {
m_log.Emsg("Factory::ConfigParameters() error parsing diskusage parameter ", minV.c_str());
return false;
}
float hwmf = strtod(maxV.c_str(), &eP);
if (errno || eP == maxV.c_str()) {
m_log.Emsg("Factory::ConfigParameters() error parsing diskusage parameter ", maxV.c_str());
return false;
}
m_configuration.m_diskUsageLWM = static_cast<long long>(sP.Total * lwmf + 0.5);
m_configuration.m_diskUsageHWM = static_cast<long long>(sP.Total * hwmf + 0.5);
}
}
}
}
else if ( part == "blocksize" )
{
long long minBSize = 64 * 1024;
long long maxBSize = 16 * 1024 * 1024;
if ( XrdOuca2x::a2sz(m_log, "get block size", config.GetWord(), &m_configuration.m_bufferSize, minBSize, maxBSize))
{
return false;
}
}
else if (part == "prefetch_max_blocks" )
{
const char* params = config.GetWord();
if (params) {
int p = ::atoi(params);
if (p > 0) {
printf("prefetch enabled, max blocks per file=%d\n", p);
m_configuration.m_prefetch_max_blocks = p;
} else {
m_log.Emsg("Config", "Prefetch is disabled");
m_configuration.m_prefetch_max_blocks = 0;
}
}
else
{
m_log.Emsg("Config", "Error setting prefetch level.");
return false;
}
}
else if (part == "ram" )
{
long long minRAM = 1024* 1024 * 1024;;
long long maxRAM = 100 * minRAM;
if ( XrdOuca2x::a2sz(m_log, "get RAM available", config.GetWord(), &m_configuration.m_RamAbsAvailable, minRAM, maxRAM))
{
return false;
}
}
else if ( part == "hdfsmode" )
{
m_configuration.m_hdfsmode = true;
const char* params = config.GetWord();
if (params) {
if (!strncmp("hdfsbsize", params, 9)) {
long long minBlSize = 128 * 1024;
long long maxBlSize = 1024 * 1024 * 1024;
params = config.GetWord();
if ( XrdOuca2x::a2sz(m_log, "Error getting file fragment size", params, &m_configuration.m_hdfsbsize, minBlSize, maxBlSize))
{
return false;
}
}
else {
m_log.Emsg("Config", "Error setting the fragment size parameter name");
return false;
}
}
}
else
{
m_log.Emsg("Cache::ConfigParameters() unmatched pfc parameter", part.c_str());
return false;
}
assert ( config.GetWord() == 0 && "Cache::ConfigParameters() lost argument");
return true;
}