39#define TS_Xeq(key, func) NoGo = (strcmp(key, var) == 0) ? func(Config) : 0
44 XrdOucStream Config(&m_log, getenv(
"XRDINSTANCE"), &myEnv,
"(Throttle Config)> ");
46 if (config_file.empty()) {
47 m_log.Say(
"No filename specified.");
50 if ((cfgFD =
open(config_file.c_str(), O_RDONLY)) < 0) {
51 m_log.Emsg(
"Config", errno,
"Unable to open configuration file", config_file.c_str());
55 static const char *cvec[] = {
"*** throttle (ofs) plugin config:", 0 };
60 while( (var = Config.GetMyFirstWord()) )
62 if (!strcmp(
"throttle.fslib", var)) {
63 val = Config.GetWord();
64 if (!val || !val[0]) {m_log.Emsg(
"Config",
"fslib not specified.");
continue;}
67 TS_Xeq(
"throttle.max_open_files", xmaxopen);
68 TS_Xeq(
"throttle.max_active_connections", xmaxconn);
69 TS_Xeq(
"throttle.throttle", xthrottle);
70 TS_Xeq(
"throttle.loadshed", xloadshed);
71 TS_Xeq(
"throttle.max_wait_time", xmaxwait);
72 TS_Xeq(
"throttle.trace", xtrace);
73 TS_Xeq(
"throttle.userconfig", xuserconfig);
76 m_log.Emsg(
"Config",
"Throttle configuration failed.");
98 auto val = Config.GetWord();
99 if (!val || val[0] ==
'\0')
100 {m_log.
Emsg(
"Config",
"Max open files not specified! Example usage: throttle.max_open_files 16000");}
101 long long max_open = -1;
102 if (
XrdOuca2x::a2sz(m_log,
"max open files value", val, &max_open, 1))
return 1;
104 m_max_open = max_open;
122Configuration::xmaxconn(XrdOucStream &Config)
124 auto val =
Config.GetWord();
125 if (!val || val[0] ==
'\0')
126 {m_log.Emsg(
"Config",
"Max active connections not specified! Example usage: throttle.max_active_connections 4000");}
127 long long max_conn = -1;
128 if (
XrdOuca2x::a2sz(m_log,
"max active connections value", val, &max_conn, 1))
return 1;
130 m_max_conn = max_conn;
149Configuration::xmaxwait(XrdOucStream &Config)
151 auto val =
Config.GetWord();
152 if (!val || val[0] ==
'\0')
153 {m_log.Emsg(
"Config",
"Max waiting time not specified (must be in seconds)! Example usage: throttle.max_wait_time 20");}
154 long long max_wait = -1;
155 if (
XrdOuca2x::a2sz(m_log,
"max waiting time value", val, &max_wait, 1))
return 1;
157 m_max_wait = max_wait;
178Configuration::xthrottle(XrdOucStream &Config)
180 long long drate = -1, irate = -1, rint = 1000, climit = -1;
183 while ((val =
Config.GetWord()))
185 if (strcmp(
"data", val) == 0)
187 if (!(val =
Config.GetWord()))
188 {m_log.Emsg(
"Config",
"data throttle limit not specified.");
return 1;}
189 if (
XrdOuca2x::a2sz(m_log,
"data throttle value",val,&drate,1))
return 1;
191 else if (strcmp(
"iops", val) == 0)
193 if (!(val =
Config.GetWord()))
194 {m_log.Emsg(
"Config",
"IOPS throttle limit not specified.");
return 1;}
195 if (
XrdOuca2x::a2sz(m_log,
"IOPS throttle value",val,&irate,1))
return 1;
197 else if (strcmp(
"rint", val) == 0)
199 if (!(val =
Config.GetWord()))
200 {m_log.Emsg(
"Config",
"recompute interval not specified (in ms).");
return 1;}
201 if (
XrdOuca2x::a2sp(m_log,
"recompute interval value (in ms)",val,&rint,10))
return 1;
203 else if (strcmp(
"concurrency", val) == 0)
205 if (!(val =
Config.GetWord()))
206 {m_log.Emsg(
"Config",
"Concurrency limit not specified.");
return 1;}
207 if (
XrdOuca2x::a2sz(m_log,
"Concurrency limit value",val,&climit,1))
return 1;
211 m_log.Emsg(
"Config",
"Warning - unknown throttle option specified", val,
".");
215 m_throttle_data_rate = drate;
216 m_throttle_iops_rate = irate;
217 m_throttle_concurrency_limit = climit;
218 m_throttle_recompute_interval_ms = rint;
238int Configuration::xloadshed(XrdOucStream &Config)
240 long long port = 0, freq = 0;
242 std::string hostname;
244 while ((val =
Config.GetWord()))
246 if (strcmp(
"host", val) == 0)
248 if (!(val =
Config.GetWord()))
249 {m_log.Emsg(
"Config",
"loadshed hostname not specified.");
return 1;}
252 else if (strcmp(
"port", val) == 0)
254 if (!(val =
Config.GetWord()))
255 {m_log.Emsg(
"Config",
"Port number not specified.");
return 1;}
258 else if (strcmp(
"frequency", val) == 0)
260 if (!(val =
Config.GetWord()))
261 {m_log.Emsg(
"Config",
"Loadshed frequency not specified.");
return 1;}
262 if (
XrdOuca2x::a2sz(m_log,
"Loadshed frequency",val,&freq,1,100))
return 1;
266 m_log.Emsg(
"Config",
"Warning - unknown loadshed option specified", val,
".");
270 if (hostname.empty())
272 m_log.Emsg(
"Config",
"must specify hostname for loadshed parameter.");
276 m_loadshed_freq = freq;
277 m_loadshed_hostname = hostname;
278 m_loadshed_port = port;
297int Configuration::xtrace(XrdOucStream &Config)
300 static const struct traceopts {
const char *opname;
int opval;} tropts[] =
312 int i, neg, trval = 0, numopts =
sizeof(tropts)/
sizeof(
struct traceopts);
314 if (!(val =
Config.GetWord()))
316 m_log.Emsg(
"Config",
"trace option not specified");
321 if (!strcmp(val,
"off"))
327 if ((neg = (val[0] ==
'-' && val[1])))
331 for (i = 0; i < numopts; i++)
333 if (!strcmp(val, tropts[i].opname))
337 if (tropts[i].opval) trval &= ~tropts[i].opval;
340 else if (tropts[i].opval) trval |= tropts[i].opval;
347 m_log.Say(
"Config warning: ignoring invalid trace option '", val,
"'.");
352 m_trace_levels = trval;
368int Configuration::xuserconfig(XrdOucStream &Config)
370 auto val =
Config.GetWord();
371 if (!val || val[0] ==
'\0')
373 m_log.Emsg(
"Config",
"User config file path not specified! Example usage: throttle.userconfig /etc/xrootd/throttle-users.conf");
return 1;
376 m_user_config_file = val;
377 m_log.Emsg(
"Config Info: using user config file at '", val,
"'.");
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)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
int Configure(const std::string &config_file)