14 #define OFS_NAME "libXrdOfs.so"
34 eDest.
Emsg(
"Config",
"Unable to load OFS filesystem.");
43 if (!(fs = (*ep)(0,
eDest.
logger(), config_file.c_str())))
45 eDest.
Emsg(
"Config",
"Unable to create file system object via", fslib.c_str());
62 FileSystem::Initialize(fs, native_fs, lp, configfn,
envP);
92 FileSystem::FileSystem()
93 : m_eroute(0), m_trace(&m_eroute), m_sfs_ptr(0), m_initialized(false), m_throttle(&m_eroute, &m_trace)
98 FileSystem::~FileSystem() {}
104 const char *configfn,
108 if (m_instance == NULL && !(m_instance =
new FileSystem()))
113 if (!fs->m_initialized)
115 fs->m_config_file = configfn;
117 fs->m_eroute.
Say(
"Initializing a Throttled file system.");
118 if (fs->Configure(fs->m_eroute, native_fs,
envP))
120 fs->m_eroute.
Say(
"Initialization of throttled file system failed.");
124 fs->m_throttle.
Init();
125 fs->m_initialized =
true;
129 #define TS_Xeq(key, func) NoGo = (strcmp(key, var) == 0) ? func(Config) : 0
136 if (m_config_file.length() == 0)
138 log.
Say(
"No filename specified.");
141 if ((cfgFD =
open(m_config_file.c_str(), O_RDONLY)) < 0)
143 log.
Emsg(
"Config", errno,
"Unable to open configuration file", m_config_file.c_str());
147 static const char *cvec[] = {
"*** throttle (ofs) plugin config:", 0 };
154 while( (var =
Config.GetMyFirstWord()) )
156 if (strcmp(
"throttle.fslib", var) == 0)
159 if (!val || !val[0]) {log.
Emsg(
"Config",
"fslib not specified.");
continue;}
162 TS_Xeq(
"throttle.max_open_files", xmaxopen);
163 TS_Xeq(
"throttle.max_active_connections", xmaxconn);
164 TS_Xeq(
"throttle.throttle", xthrottle);
165 TS_Xeq(
"throttle.loadshed", xloadshed);
166 TS_Xeq(
"throttle.trace", xtrace);
169 log.
Emsg(
"Config",
"Throttle configuration failed.");
174 m_sfs_ptr = native_fs ? native_fs :
LoadFS(fslib, m_eroute, m_config_file);
175 if (!m_sfs_ptr)
return 1;
183 log.
Say(
"Config",
"Throttle g-stream has", gstream ?
"" :
" NOT",
" been configured via xrootd.mongstream directive");
209 auto val =
Config.GetWord();
210 if (!val || val[0] ==
'\0')
211 {m_eroute.
Emsg(
"Config",
"Max open files not specified! Example usage: throttle.max_open_files 16000");}
212 long long max_open = -1;
213 if (
XrdOuca2x::a2sz(m_eroute,
"max open files value", val, &max_open, 1))
return 1;
235 auto val =
Config.GetWord();
236 if (!val || val[0] ==
'\0')
237 {m_eroute.
Emsg(
"Config",
"Max active cconnections not specified! Example usage: throttle.max_active_connections 4000");}
238 long long max_conn = -1;
239 if (
XrdOuca2x::a2sz(m_eroute,
"max active connections value", val, &max_conn, 1))
return 1;
264 long long drate = -1, irate = -1, rint = 1000, climit = -1;
267 while ((val =
Config.GetWord()))
269 if (strcmp(
"data", val) == 0)
271 if (!(val =
Config.GetWord()))
272 {m_eroute.
Emsg(
"Config",
"data throttle limit not specified.");
return 1;}
273 if (
XrdOuca2x::a2sz(m_eroute,
"data throttle value",val,&drate,1))
return 1;
275 else if (strcmp(
"iops", val) == 0)
277 if (!(val =
Config.GetWord()))
278 {m_eroute.
Emsg(
"Config",
"IOPS throttle limit not specified.");
return 1;}
279 if (
XrdOuca2x::a2sz(m_eroute,
"IOPS throttle value",val,&irate,1))
return 1;
281 else if (strcmp(
"rint", val) == 0)
283 if (!(val =
Config.GetWord()))
284 {m_eroute.
Emsg(
"Config",
"recompute interval not specified.");
return 1;}
285 if (
XrdOuca2x::a2sp(m_eroute,
"recompute interval value",val,&rint,10))
return 1;
287 else if (strcmp(
"concurrency", val) == 0)
289 if (!(val =
Config.GetWord()))
290 {m_eroute.
Emsg(
"Config",
"Concurrency limit not specified.");
return 1;}
291 if (
XrdOuca2x::a2sz(m_eroute,
"Concurrency limit value",val,&climit,1))
return 1;
295 m_eroute.
Emsg(
"Config",
"Warning - unknown throttle option specified", val,
".");
299 m_throttle.
SetThrottles(drate, irate, climit,
static_cast<float>(rint)/1000.0);
320 long long port = 0, freq = 0;
322 std::string hostname;
324 while ((val =
Config.GetWord()))
326 if (strcmp(
"host", val) == 0)
328 if (!(val =
Config.GetWord()))
329 {m_eroute.
Emsg(
"Config",
"loadshed hostname not specified.");
return 1;}
332 else if (strcmp(
"port", val) == 0)
334 if (!(val =
Config.GetWord()))
335 {m_eroute.
Emsg(
"Config",
"Port number not specified.");
return 1;}
336 if (
XrdOuca2x::a2sz(m_eroute,
"Port number",val,&port,1, 65536))
return 1;
338 else if (strcmp(
"frequency", val) == 0)
340 if (!(val =
Config.GetWord()))
341 {m_eroute.
Emsg(
"Config",
"Loadshed frequency not specified.");
return 1;}
342 if (
XrdOuca2x::a2sz(m_eroute,
"Loadshed frequency",val,&freq,1,100))
return 1;
346 m_eroute.
Emsg(
"Config",
"Warning - unknown loadshed option specified", val,
".");
350 if (hostname.empty())
352 m_eroute.
Emsg(
"Config",
"must specify hostname for loadshed parameter.");
377 static const struct traceopts {
const char *opname;
int opval;} tropts[] =
389 int i, neg, trval = 0, numopts =
sizeof(tropts)/
sizeof(
struct traceopts);
391 if (!(val =
Config.GetWord()))
393 m_eroute.
Emsg(
"Config",
"trace option not specified");
398 if (!strcmp(val,
"off"))
404 if ((neg = (val[0] ==
'-' && val[1])))
408 for (i = 0; i < numopts; i++)
410 if (!strcmp(val, tropts[i].opname))
414 if (tropts[i].opval) trval &= ~tropts[i].opval;
417 else if (tropts[i].opval) trval |= tropts[i].opval;
424 m_eroute.
Say(
"Config warning: ignoring invalid trace option '", val,
"'.");
429 m_trace.
What = trval;
static XrdSysError eDest(0,"crypto_")
XrdSfsFileSystem * XrdSfsGetDefaultFileSystem(XrdSfsFileSystem *native_fs, XrdSysLogger *lp, const char *configfn, XrdOucEnv *EnvInfo)
static XrdSfsFileSystem * LoadFS(const std::string &fslib, XrdSysError &eDest, const std::string &config_file)
XrdSfsFileSystem * XrdSfsGetFileSystem2(XrdSfsFileSystem *native_fs, XrdSysLogger *lp, const char *configfn, XrdOucEnv *envP)
#define TS_Xeq(key, func)
XrdSfsFileSystem * XrdSfsGetFileSystem(XrdSfsFileSystem *native_fs, XrdSysLogger *lp, const char *configfn)
XrdVERSIONINFO(XrdSfsGetFileSystem, FileSystem)
static int Export(const char *Var, const char *Val)
void * GetPtr(const char *varname)
static int a2sp(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
uint64_t FeatureSet
Adjust features at initialization.
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
void * getPlugin(const char *pname, int optional=0)
void SetThrottles(float reqbyterate, float reqoprate, int concurrency, float interval_length)
void SetMaxOpen(unsigned long max_open)
void SetLoadShed(std::string &hostname, unsigned port, unsigned frequency)
void SetMonitor(XrdXrootdGStream *gstream)
void SetMaxConns(unsigned long max_conns)
XrdSfsFileSystem * XrdSfsGetFileSystem_Internal(XrdSfsFileSystem *native_fs, XrdSysLogger *lp, const char *configfn, XrdOucEnv *envP)