15 #define TS_Xeq(key, func) NoGo = (strcmp(key, var) == 0) ? func(Config) : 0
22 if (config_file.empty()) {
23 m_log.
Say(
"No filename specified.");
26 if ((cfgFD =
open(config_file.c_str(), O_RDONLY)) < 0) {
27 m_log.
Emsg(
"Config", errno,
"Unable to open configuration file", config_file.c_str());
31 static const char *cvec[] = {
"*** throttle (ofs) plugin config:", 0 };
36 while( (var =
Config.GetMyFirstWord()) )
38 if (!strcmp(
"throttle.fslib", var)) {
40 if (!val || !val[0]) {m_log.
Emsg(
"Config",
"fslib not specified.");
continue;}
43 TS_Xeq(
"throttle.max_open_files", xmaxopen);
44 TS_Xeq(
"throttle.max_active_connections", xmaxconn);
45 TS_Xeq(
"throttle.throttle", xthrottle);
46 TS_Xeq(
"throttle.loadshed", xloadshed);
47 TS_Xeq(
"throttle.max_wait_time", xmaxwait);
48 TS_Xeq(
"throttle.trace", xtrace);
51 m_log.
Emsg(
"Config",
"Throttle configuration failed.");
73 auto val =
Config.GetWord();
74 if (!val || val[0] ==
'\0')
75 {m_log.
Emsg(
"Config",
"Max open files not specified! Example usage: throttle.max_open_files 16000");}
76 long long max_open = -1;
77 if (
XrdOuca2x::a2sz(m_log,
"max open files value", val, &max_open, 1))
return 1;
79 m_max_open = max_open;
99 auto val =
Config.GetWord();
100 if (!val || val[0] ==
'\0')
101 {m_log.
Emsg(
"Config",
"Max active connections not specified! Example usage: throttle.max_active_connections 4000");}
102 long long max_conn = -1;
103 if (
XrdOuca2x::a2sz(m_log,
"max active connections value", val, &max_conn, 1))
return 1;
105 m_max_conn = max_conn;
126 auto val =
Config.GetWord();
127 if (!val || val[0] ==
'\0')
128 {m_log.
Emsg(
"Config",
"Max waiting time not specified (must be in seconds)! Example usage: throttle.max_wait_time 20");}
129 long long max_wait = -1;
130 if (
XrdOuca2x::a2sz(m_log,
"max waiting time value", val, &max_wait, 1))
return 1;
153 long long drate = -1, irate = -1, rint = 1000, climit = -1;
156 while ((val =
Config.GetWord()))
158 if (strcmp(
"data", val) == 0)
160 if (!(val =
Config.GetWord()))
161 {m_log.
Emsg(
"Config",
"data throttle limit not specified.");
return 1;}
162 if (
XrdOuca2x::a2sz(m_log,
"data throttle value",val,&drate,1))
return 1;
164 else if (strcmp(
"iops", val) == 0)
166 if (!(val =
Config.GetWord()))
167 {m_log.
Emsg(
"Config",
"IOPS throttle limit not specified.");
return 1;}
168 if (
XrdOuca2x::a2sz(m_log,
"IOPS throttle value",val,&irate,1))
return 1;
170 else if (strcmp(
"rint", val) == 0)
172 if (!(val =
Config.GetWord()))
173 {m_log.
Emsg(
"Config",
"recompute interval not specified (in ms).");
return 1;}
174 if (
XrdOuca2x::a2sp(m_log,
"recompute interval value (in ms)",val,&rint,10))
return 1;
176 else if (strcmp(
"concurrency", val) == 0)
178 if (!(val =
Config.GetWord()))
179 {m_log.
Emsg(
"Config",
"Concurrency limit not specified.");
return 1;}
180 if (
XrdOuca2x::a2sz(m_log,
"Concurrency limit value",val,&climit,1))
return 1;
184 m_log.
Emsg(
"Config",
"Warning - unknown throttle option specified", val,
".");
188 m_throttle_data_rate = drate;
189 m_throttle_iops_rate = irate;
190 m_throttle_concurrency_limit = climit;
191 m_throttle_recompute_interval_ms = rint;
213 long long port = 0, freq = 0;
215 std::string hostname;
217 while ((val =
Config.GetWord()))
219 if (strcmp(
"host", val) == 0)
221 if (!(val =
Config.GetWord()))
222 {m_log.
Emsg(
"Config",
"loadshed hostname not specified.");
return 1;}
225 else if (strcmp(
"port", val) == 0)
227 if (!(val =
Config.GetWord()))
228 {m_log.
Emsg(
"Config",
"Port number not specified.");
return 1;}
231 else if (strcmp(
"frequency", val) == 0)
233 if (!(val =
Config.GetWord()))
234 {m_log.
Emsg(
"Config",
"Loadshed frequency not specified.");
return 1;}
235 if (
XrdOuca2x::a2sz(m_log,
"Loadshed frequency",val,&freq,1,100))
return 1;
239 m_log.
Emsg(
"Config",
"Warning - unknown loadshed option specified", val,
".");
243 if (hostname.empty())
245 m_log.
Emsg(
"Config",
"must specify hostname for loadshed parameter.");
249 m_loadshed_freq = freq;
250 m_loadshed_hostname = hostname;
251 m_loadshed_port = port;
273 static const struct traceopts {
const char *opname;
int opval;} tropts[] =
285 int i, neg, trval = 0, numopts =
sizeof(tropts)/
sizeof(
struct traceopts);
287 if (!(val =
Config.GetWord()))
289 m_log.
Emsg(
"Config",
"trace option not specified");
294 if (!strcmp(val,
"off"))
300 if ((neg = (val[0] ==
'-' && val[1])))
304 for (i = 0; i < numopts; i++)
306 if (!strcmp(val, tropts[i].opname))
310 if (tropts[i].opval) trval &= ~tropts[i].opval;
313 else if (tropts[i].opval) trval |= tropts[i].opval;
320 m_log.
Say(
"Config warning: ignoring invalid trace option '", val,
"'.");
325 m_trace_levels = trval;
#define TS_Xeq(key, func)
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)
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)
int Configure(const std::string &config_file)