XRootD
XrdOucPsx.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d O u c P s x . c c */
4 /* */
5 /* (c) 2017 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include <unistd.h>
32 #include <cctype>
33 #include <cstdio>
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <fcntl.h>
38 
39 #include "XrdOuc/XrdOuca2x.hh"
40 #include "XrdOuc/XrdOucCache.hh"
41 #include "XrdOuc/XrdOucEnv.hh"
45 #include "XrdOuc/XrdOucPsx.hh"
46 #include "XrdOuc/XrdOucStream.hh"
47 #include "XrdOuc/XrdOucTList.hh"
48 #include "XrdOuc/XrdOucUtils.hh"
49 
50 #include "XrdSys/XrdSysError.hh"
51 #include "XrdSys/XrdSysLogger.hh"
52 #include "XrdSys/XrdSysPlatform.hh"
53 
54 /******************************************************************************/
55 /* d e f i n e s */
56 /******************************************************************************/
57 
58 #define Duplicate(x,y) if (y) free(y); y = strdup(x)
59 
60 #define TS_String(x,m) if (!strcmp(x,var)) {Duplicate(val,m); return 0;}
61 
62 #define TS_Xeq(x,m) if (!strcmp(x,var)) return m(&eDest, Config);
63 
64 /*******x**********************************************************************/
65 /* G l o b a l s */
66 /******************************************************************************/
67 
68 namespace
69 {
70 XrdSysLogger *logP = 0;
71 bool warn = false;
72 }
73 
74 /******************************************************************************/
75 /* D e s t r u c t o r */
76 /******************************************************************************/
77 
79 {
80  XrdOucTList *tP;
81 
82  if (mCache) free(mCache);
83  if (LocalRoot) free(LocalRoot);
84  if (RemotRoot) free(RemotRoot);
85  if (N2NLib) free(N2NLib);
86  if (N2NParms) free(N2NParms);
87  if (cPath) free(cPath);
88  if (cParm) free(cParm);
89  if (mPath) free(mPath);
90  if (mParm) free(mParm);
91  if (configFN) free(configFN);
92 
93  while((tP = setFirst)) {setFirst = tP->next; delete tP;}
94 }
95 
96 /******************************************************************************/
97 /* C l i e n t C o n f i g */
98 /******************************************************************************/
99 
100 bool XrdOucPsx::ClientConfig(const char *pfx, bool hush)
101 {
102 /*
103  Function: Establish configuration at start up time.
104 
105  Input: None.
106 
107  Output: 0 upon success or !0 otherwise.
108 */
109  XrdOucEnv myEnv;
110  const char *theIname = "*client anon@localhost";
111  XrdOucTListFIFO tFifo;
112  char *var;
113  int cfgFD, retc, pfxlen = strlen(pfx);
114  bool aOK = true;
115 
116 // Export the instance name as this is used in all sort of places
117 //
118  XrdOucEnv::Export("XRDINSTANCE", theIname);
119 
120 // We must establish a stable logger for client-side configs. The error and
121 // stream objects can be temporary.
122 //
123  logP = new XrdSysLogger;
124  XrdSysError eDest(logP, "psx");
125  XrdOucStream Config(&eDest, theIname, &myEnv, "=====> ");
126 
127 // Try to open the configuration file.
128 //
129  if ((cfgFD = open(configFN, O_RDONLY, 0)) < 0)
130  {eDest.Emsg("Config", errno, "open config file", configFN);
131  return false;
132  }
133  Config.Attach(cfgFD);
134 
135 // Capture all lines going to stderr if so wanted
136 //
137  if (hush) logP->Capture(&tFifo);
138 
139 // Now start reading records until eof.
140 //
141  while((var = Config.GetMyFirstWord()))
142  {if (!strncmp(var, pfx, pfxlen) && !Parse(var+pfxlen, Config, eDest))
143  {Config.Echo(); aOK = false;}
144  }
145 
146 // Check if we should blither about any warnings or errors
147 //
148  if (hush)
149  {logP->Capture(0);
150  if ((!aOK || warn) && tFifo.first) WarnConfig(eDest, tFifo.first, !aOK);
151  tFifo.Clear();
152  }
153 
154 // Now check if any errors occurred during file i/o
155 //
156  if ((retc = Config.LastError()))
157  {eDest.Emsg("Config", retc, "read config file", configFN); aOK = false;}
158  Config.Close();
159 
160 
161 // If all went well, materialize the configuration and return result
162 //
163  if (aOK) return ConfigSetup(eDest, hush);
164  return false;
165 }
166 
167 /******************************************************************************/
168 /* Private: C o n f i g C a c h e */
169 /******************************************************************************/
170 
171 bool XrdOucPsx::ConfigCache(XrdSysError &eDest)
172 {
173  XrdOucPinLoader myLib(&eDest,myVersion,"cachelib",cPath);
174 
175 // Get the cache Object now
176 //
177  XrdOucCache_t ep = (XrdOucCache_t)myLib.Resolve("XrdOucGetCache");
178  if (!ep) return false;
179  theCache = (XrdOucCache*)ep(eDest.logger(), configFN, cParm, theEnv);
180  return theCache != 0;
181 }
182 
183 /******************************************************************************/
184 /* C o n f i g N 2 N */
185 /******************************************************************************/
186 
187 bool XrdOucPsx::ConfigN2N(XrdSysError &eDest)
188 {
189  XrdOucN2NLoader n2nLoader(&eDest, configFN, N2NParms, LocalRoot, RemotRoot);
190 
191 // Skip all of this we are not doing name mapping.
192 //
193  if (!N2NLib && !LocalRoot)
194  {xLfn2Pfn = false;
195  xPfn2Lfn = xP2Loff;
196  return true;
197  }
198 
199 // Check if the n2n is applicable
200 //
201  if (xPfn2Lfn && !(mCache || cPath) && N2NLib)
202  {const char *txt = (xLfn2Pfn ? "-lfncache option" : "directive");
203  eDest.Say("Config warning: ignoring namelib ", txt,
204  "; caching not in effect!");
205  if (!xLfn2Pfn) return true;
206  }
207 
208 // Get the plugin
209 //
210  return (theN2N = n2nLoader.Load(N2NLib, *myVersion)) != 0;
211 }
212 
213 /******************************************************************************/
214 /* C o n f i g S e t u p */
215 /******************************************************************************/
216 
218 {
219  XrdOucTListFIFO tFifo;
220  bool aOK = true;
221 
222 // Handle hush option for client-side configs
223 //
224  if (hush) eDest.logger()->Capture(&tFifo);
225 
226 // Initialize an alternate cache if one is present and load a CCM if need be
227 //
228  if (cPath && !ConfigCache(eDest))
229  {aOK = false;
230  if (hush)
231  {eDest.logger()->Capture(0);
232  WarnPlugin(eDest, tFifo.first, "cachelib", cPath);
233  tFifo.Clear();
234  eDest.logger()->Capture(&tFifo);
235  }
236  } else {
237  if (mPath && theCache && !LoadCCM(eDest))
238  {aOK = false;
239  if (hush)
240  {eDest.logger()->Capture(0);
241  WarnPlugin(eDest, tFifo.first, "ccmlib", mPath);
242  tFifo.Clear();
243  eDest.logger()->Capture(&tFifo);
244  }
245  }
246  }
247 
248 // Configure the N2N library:
249 //
250  if (!ConfigN2N(eDest))
251  {aOK = false;
252  if (hush)
253  {eDest.logger()->Capture(0);
254  if (N2NLib) WarnPlugin(eDest,tFifo.first,"namelib",N2NLib);
255  else WarnPlugin(eDest,tFifo.first,"name2name for",LocalRoot);
256  tFifo.Clear();
257  }
258  }
259 
260 // All done
261 //
262  if (hush) eDest.logger()->Capture(0);
263  return aOK;
264 }
265 
266 /******************************************************************************/
267 /* Private: L o a d C C M */
268 /******************************************************************************/
269 
270 bool XrdOucPsx::LoadCCM(XrdSysError &eDest)
271 {
272  XrdOucPinLoader myLib(&eDest,myVersion,"ccmlib",mPath);
273 
274 // Resolve the context manager entry point
275 //
276  initCCM = (XrdOucCacheCMInit_t)myLib.Resolve("XrdOucCacheCMInit");
277  return initCCM != 0;
278 }
279 
280 /******************************************************************************/
281 /* P a r s e */
282 /******************************************************************************/
283 
284 bool XrdOucPsx::Parse(char *var, XrdOucStream &Config, XrdSysError &eDest)
285 {
286 
287  // Process items. for either a local or a remote configuration
288  //
289  TS_Xeq("memcache", ParseCache); // Backward compatibility
290  TS_Xeq("cache", ParseCache);
291  TS_Xeq("cachelib", ParseCLib);
292  TS_Xeq("ccmlib", ParseMLib);
293  TS_Xeq("ciosync", ParseCio);
294  TS_Xeq("inetmode", ParseINet);
295  TS_Xeq("namelib", ParseNLib);
296  TS_Xeq("setopt", ParseSet);
297  TS_Xeq("trace", ParseTrace);
298 
299  // No match found, complain.
300  //
301  eDest.Say("Config warning: ignoring unknown directive '",var,"'.");
302  warn = true;
303  Config.Echo();
304  return true;
305 }
306 
307 /******************************************************************************/
308 /* P a r s e C a c h e */
309 /******************************************************************************/
310 
311 /* Function: ParseCache
312 
313  Purpose: To parse the directive: cache <keyword> <value> [...]
314 
315  <keyword> is one of the following:
316  debug {0 | 1 | 2}
317  logstats enables stats logging
318  max2cache largest read to cache (can be suffixed with k, m, g).
319  minpages smallest number of pages allowed (default 256)
320  mode {r | w}
321  pagesize size of each cache page (can be suffixed with k, m, g).
322  preread [minpages [minrdsz]] [perf nn [recalc]]
323  r/w enables caching for files opened read/write.
324  sfiles {on | off | .<sfx>}
325  size size of cache in bytes (can be suffixed with k, m, g).
326 
327  Output: true upon success or false upon failure.
328 */
329 
331 {
332  long long llVal, cSize=-1, m2Cache=-1, pSize=-1, minPg = -1;
333  const char *ivN = 0;
334  char *val, *sfSfx = 0, sfVal = '0', lgVal = '0', dbVal = '0', rwVal = '0';
335  char eBuff[2048], pBuff[1024], *eP;
336  struct sztab {const char *Key; long long *Val;} szopts[] =
337  {{"max2cache", &m2Cache},
338  {"minpages", &minPg},
339  {"pagesize", &pSize},
340  {"size", &cSize}
341  };
342  int i, numopts = sizeof(szopts)/sizeof(struct sztab);
343 
344 // Delete any cache parameters we may have
345 //
346  if (mCache) {free(mCache); mCache = 0;}
347 
348 // If we have no parameters, then we just use the defaults
349 //
350  if (!(val = Config.GetWord()))
351  {mCache = strdup("mode=s&optwr=0"); return true;}
352  *pBuff = 0;
353 
354 do{for (i = 0; i < numopts; i++) if (!strcmp(szopts[i].Key, val)) break;
355 
356  if (i < numopts)
357  {if (!(val = Config.GetWord())) ivN = szopts[i].Key;
358  else if (XrdOuca2x::a2sz(*Eroute,szopts[i].Key,val,&llVal,0))
359  return false;
360  else *(szopts[i].Val) = llVal;
361  } else {
362  if (!strcmp("debug", val))
363  {if (!(val = Config.GetWord())
364  || ((*val < '0' || *val > '3') && !*(val+1))) ivN = "debug";
365  else dbVal = *val;
366  }
367  else if (!strcmp("logstats", val)) lgVal = '1';
368  else if (!strcmp("preread", val))
369  {if ((val = ParseCache(Eroute, Config, pBuff))) continue;
370  if (*pBuff == '?') return false;
371  break;
372  }
373  else if (!strcmp("r/w", val)) rwVal = '1';
374  else if (!strcmp("sfiles", val))
375  {if (sfSfx) {free(sfSfx); sfSfx = 0;}
376  if (!(val = Config.GetWord())) ivN = "sfiles";
377  else if (!strcmp("on", val)) sfVal = '1';
378  else if (!strcmp("off", val)) sfVal = '0';
379  else if (*val == '.' && strlen(val) < 16) sfSfx = strdup(val);
380  else ivN = "sfiles";
381  }
382  else {Eroute->Emsg("Config","invalid cache keyword -", val);
383  return false;
384  }
385  }
386 
387  if (ivN)
388  {if (!val) Eroute->Emsg("Config","cache", ivN,"value not specified.");
389  else Eroute->Emsg("Config", val, "is invalid for cache", ivN);
390  return false;
391  }
392  } while ((val = Config.GetWord()));
393 
394 // Construct the envar string
395 //
396  strcpy(eBuff, "mode=s&maxfiles=16384"); eP = eBuff + strlen(eBuff);
397  if (cSize > 0) eP += sprintf(eP, "&cachesz=%lld", cSize);
398  if (dbVal != '0') eP += sprintf(eP, "&debug=%c", dbVal);
399  if (m2Cache > 0) eP += sprintf(eP, "&max2cache=%lld", m2Cache);
400  if (minPg > 0)
401  {if (minPg > 32767) minPg = 32767;
402  eP += sprintf(eP, "&minpages=%lld", minPg);
403  }
404  if (pSize > 0) eP += sprintf(eP, "&pagesz=%lld", pSize);
405  if (lgVal != '0') strcat(eP, "&optlg=1");
406  if (sfVal != '0' || sfSfx)
407  {if (!sfSfx) strcat(eP, "&optsf=1");
408  else {strcat(eP, "&optsf="); strcat(eBuff, sfSfx); free(sfSfx);}
409  }
410  if (rwVal != '0') strcat(eP, "&optwr=1");
411  if (*pBuff) strcat(eP, pBuff);
412 
413  mCache = strdup(eBuff);
414  return true;
415 }
416 
417 /******************************************************************************/
418 
419 /* Parse the directive: preread [pages [minrd]] [perf pct [calc]]
420 
421  pages minimum number of pages to preread.
422  minrd minimum size of read (can be suffixed with k, m, g).
423  perf preread performance (0 to 100).
424  calc calc perf every n bytes (can be suffixed with k, m, g).
425 */
426 
427 char *XrdOucPsx::ParseCache(XrdSysError *Eroute, XrdOucStream &Config, char *pBuff)
428 {
429  long long minr = 0, maxv = 0x7fffffff, recb = 50*1024*1024;
430  int minp = 1, perf = 90, Spec = 0;
431  char *val;
432 
433 // Check for our options
434 //
435  *pBuff = '?';
436  if ((val = Config.GetWord()) && isdigit(*val))
437  {if (XrdOuca2x::a2i(*Eroute,"preread pages",val,&minp,0,32767)) return 0;
438  if ((val = Config.GetWord()) && isdigit(*val))
439  {if (XrdOuca2x::a2sz(*Eroute,"preread rdsz",val,&minr,0,maxv))
440  return 0;
441  val = Config.GetWord();
442  }
443  Spec = 1;
444  }
445  if (val && !strcmp("perf", val))
446  {if (!(val = Config.GetWord()))
447  {Eroute->Emsg("Config","cache", "preread perf value not specified.");
448  return 0;
449  }
450  if (XrdOuca2x::a2i(*Eroute,"perf",val,&perf,0,100)) return 0;
451  if ((val = Config.GetWord()) && isdigit(*val))
452  {if (XrdOuca2x::a2sz(*Eroute,"perf recalc",val,&recb,0,maxv))
453  return 0;
454  val = Config.GetWord();
455  }
456  Spec = 1;
457  }
458 
459 // Construct new string
460 //
461  if (!Spec) strcpy(pBuff,"&optpr=1&aprminp=1");
462  else sprintf(pBuff, "&optpr=1&aprtrig=%lld&aprminp=%d&aprcalc=%lld"
463  "&aprperf=%d",minr,minp,recb,perf);
464  return val;
465 }
466 
467 /******************************************************************************/
468 /* P a r s e C i o */
469 /******************************************************************************/
470 
471 /* Function: ParseCio
472 
473  Purpose: To parse the directive: ciosync <tsec> <tries>
474 
475  <tsec> the number of seconds between each sync attempt.
476  <tries> the maximum number of tries before giving up.
477 
478  Output: true upon success or false upon failure.
479 */
480 
482 {
483  char *val;
484  int tsec, mtry;
485 
486 // Get the try seconds
487 //
488  if (!(val = Config.GetWord()) || !val[0])
489  {Eroute->Emsg("Config", "ciosync parameter not specified"); return false;}
490 
491 // Convert to seconds
492 //
493  if (XrdOuca2x::a2i(*Eroute,"ciosync interval",val,&tsec,10)) return false;
494 
495 // Get the max seconds
496 //
497  if (!(val = Config.GetWord()) || !val[0])
498  {Eroute->Emsg("Config", "max time not specified"); return false;}
499 
500 // Convert to seconds
501 //
502  if (XrdOuca2x::a2i(*Eroute,"ciosync max time",val,&mtry,2)) return false;
503 
504 // Set values and return success
505 //
506  cioWait = tsec;
507  cioTries = mtry;
508  return true;
509 }
510 
511 /******************************************************************************/
512 /* P a r s e C L i b */
513 /******************************************************************************/
514 
515 /* Function: ParseCLib
516 
517  Purpose: To parse the directive: cachelib {<path>|default} [<parms>]
518 
519  <path> the path of the cache library to be used.
520  <parms> optional parms to be passed
521 
522  Output: true upon success or false upon failure.
523 */
524 
526 {
527  char *val, parms[2048];
528 
529 // Get the path and parms
530 //
531  if (!(val = Config.GetWord()) || !val[0])
532  {Eroute->Emsg("Config", "cachelib not specified"); return false;}
533 
534 // Save the path
535 //
536  if (cPath) free(cPath);
537  if (!strcmp(val,"libXrdFileCache.so") || !strcmp(val,"libXrdFileCache-4.so"))
538  {Eroute->Say("Config warning: 'libXrdFileCache' has been replaced by "
539  "'libXrdPfc'; for future compatibility specify 'default' instead!");
540  cPath = strdup("libXrdPfc.so");
541  } else {
542  cPath = (strcmp(val,"default") ? strdup(val) : strdup("libXrdPfc.so"));
543  }
544 
545 // Get the parameters
546 //
547  if (!Config.GetRest(parms, sizeof(parms)))
548  {Eroute->Emsg("Config", "cachelib parameters too long"); return false;}
549  if (cParm) free(cParm);
550  cParm = (*parms ? strdup(parms) : 0);
551 
552 // All done
553 //
554  return true;
555 }
556 
557 /******************************************************************************/
558 /* P a r s e M L i b */
559 /******************************************************************************/
560 
561 /* Function: ParseCLib
562 
563  Purpose: To parse the directive: ccmlib <path> [<parms>]
564 
565  <path> the path of the cache context mgmt library to be used.
566  <parms> optional parms to be passed
567 
568  Output: true upon success or false upon failure.
569 */
570 
572 {
573  char *val, parms[2048];
574 
575 // Get the path and parms
576 //
577  if (!(val = Config.GetWord()) || !val[0])
578  {Eroute->Emsg("Config", "ccmlib not specified"); return false;}
579 
580 // Save the path
581 //
582  if (mPath) free(mPath);
583  mPath = strdup(val);
584 
585 // Get the parameters
586 //
587  if (!Config.GetRest(parms, sizeof(parms)))
588  {Eroute->Emsg("Config", "ccmlib parameters too long"); return false;}
589  if (mParm) free(mParm);
590  mParm = (*parms ? strdup(parms) : 0);
591 
592 // All done
593 //
594  return true;
595 }
596 
597 /******************************************************************************/
598 /* P a r s e I N e t */
599 /******************************************************************************/
600 
601 /* Function: ParseINet
602 
603  Purpose: To parse the directive: inetmode v4 | v6
604 
605  v4 use only IPV4 addresses to connect to servers.
606  v6 use IPV4 mapped addresses or IPV6 addresses, as needed.
607 
608  Output: true upon success or false upon failure.
609 */
610 
612 {
613  char *val;
614 
615 // Get the mode
616 //
617  if (!(val = Config.GetWord()) || !val[0])
618  {Eroute->Emsg("Config", "inetmode value not specified"); return false;}
619 
620 // Validate the value
621 //
622  if (!strcmp(val, "v4")) useV4 = true;
623  else if (!strcmp(val, "v6")) useV4 = false;
624  else {Eroute->Emsg("Config", "invalid inetmode value -", val); return false;}
625 
626 // All done
627 //
628  return true;
629 }
630 
631 /******************************************************************************/
632 /* P a r s e N L i b */
633 /******************************************************************************/
634 
635 /* Function: ParseNLib
636 
637  Purpose: To parse the directive: namelib [<opts>] pfn<path> [<parms>]
638 
639  <opts> one or more: [-lfn2pfn] [-lfncache[src[+]]]
640  <path> the path of the filesystem library to be used.
641  <parms> optional parms to be passed
642 
643  Output: true upon success or false upon failure.
644 */
645 
647 {
648  char *val, parms[1024];
649  bool l2p = false, p2l = false, p2lsrc = false, p2lsgi = false;
650 
651 // Parse options, if any
652 //
653  while((val = Config.GetWord()) && val[0])
654  { if (!strcmp(val, "-lfn2pfn")) l2p = true;
655  else if (!strcmp(val, "-lfncache")) p2l = true;
656  else if (!strcmp(val, "-lfncachesrc")) p2l = p2lsrc = true;
657  else if (!strcmp(val, "-lfncachesrc+")) p2l = p2lsgi = true;
658  else break;
659  }
660 
661  if (!l2p && !p2l) l2p = true;
662  xLfn2Pfn = l2p;
663  if (!p2l) xPfn2Lfn = xP2Loff;
664  else if (p2lsrc) xPfn2Lfn = xP2Lsrc;
665  else if (p2lsgi) xPfn2Lfn = xP2Lsgi;
666  else xPfn2Lfn = xP2Lon;
667 
668 // Get the path
669 //
670  if (!val || !val[0])
671  {Eroute->Emsg("Config", "namelib not specified"); return false;}
672  xNameLib = true;
673 
674 // Record the path
675 //
676  if (N2NLib) free(N2NLib);
677  N2NLib = strdup(val);
678 
679 // Record any parms
680 //
681  if (!Config.GetRest(parms, sizeof(parms)))
682  {Eroute->Emsg("Config", "namelib parameters too long"); return false;}
683  if (N2NParms) free(N2NParms);
684  N2NParms = (*parms ? strdup(parms) : 0);
685  return true;
686 }
687 
688 /******************************************************************************/
689 /* P a r s e S e t */
690 /******************************************************************************/
691 
692 /* Function: ParseSet
693 
694  Purpose: To parse the directive: setopt <keyword> <value>
695 
696  <keyword> is an XrdClient option keyword.
697  <value> is the value the option is to have.
698 
699  Output: true upon success or false upon failure.
700 */
701 
703 {
704  char kword[256], *val;
705  int kval, noGo;
706  static struct sopts {const char *Sopt; const char *Copt; int isT;} Sopts[] =
707  {
708  {"ConnectTimeout", "ConnectionWindow",1}, // Default 120
709  {"ConnectionRetry", "ConnectionRetry",1}, // Default 5
710  {"DataServerTTL", "DataServerTTL",1}, // Default 300
711  {"DataServerConn_ttl", "DataServerTTL",1}, // Default 300
712  {"DebugLevel", "*",0}, // Default -1
713  {"DebugMask", "*",0}, // Default -1
714  {"DirlistAll", "DirlistAll",0},
715  {"DataServerTTL", "DataServerTTL",1}, // Default 300
716  {"LBServerConn_ttl", "LoadBalancerTTL",1}, // Default 1200
717  {"LoadBalancerTTL", "LoadBalancerTTL",1}, // Default 1200
718  {"ParallelEvtLoop", "ParallelEvtLoop",0}, // Default 10
719  {"ParStreamsPerPhyConn", "SubStreamsPerChannel",0},// Default 1
720  {"ReadAheadSize", 0,0},
721  {"ReadAheadStrategy", 0,0},
722  {"ReadCacheBlkRemPolicy", 0,0},
723  {"ReadCacheSize", 0,0},
724  {"ReadTrimBlockSize", 0,0},
725  {"ReconnectWait", "StreamErrorWindow",1}, // Default 1800
726  {"RedirCntTimeout", "!use RedirectLimit instead.",0},
727  {"RedirectLimit", "RedirectLimit",0}, // Default 16
728  {"RedirectorConn_ttl", "LoadBalancerTTL",1}, // Default 1200
729  {"RemoveUsedCacheBlocks", 0,0},
730  {"RequestTimeout", "RequestTimeout",1}, // Default 1800
731  {"StreamTimeout", "StreamTimeout",1},
732  {"TransactionTimeout", "",1},
733  {"WorkerThreads", "WorkerThreads",0} // Set To 64
734  };
735  int i, numopts = sizeof(Sopts)/sizeof(struct sopts);
736 
737  if (!(val = Config.GetWord()))
738  {Eroute->Emsg("Config", "setopt keyword not specified"); return false;}
739  strlcpy(kword, val, sizeof(kword));
740  if (!(val = Config.GetWord()))
741  {Eroute->Emsg("Config", "setopt", kword, "value not specified");
742  return false;
743  }
744 
745  for (i = 0; i < numopts; i++)
746  if (!strcmp(Sopts[i].Sopt, kword))
747  {if (!Sopts[i].Copt || *(Sopts[i].Copt) == '!')
748  {Eroute->Emsg("Config", kword, "no longer supported;",
749  (Sopts[i].Copt ? Sopts[i].Copt+1 : "ignored"));
750  } else if (*(Sopts[i].Copt))
751  {noGo = (Sopts[i].isT
752  ? XrdOuca2x::a2tm(*Eroute,kword,val,&kval)
753  : XrdOuca2x::a2i (*Eroute,kword,val,&kval));
754  if (noGo) return false;
755  if (*(Sopts[i].Copt) == '*') debugLvl = kval;
756  else ParseSet(Sopts[i].Copt, kval);
757  }
758  return true;
759  }
760 
761  Eroute->Say("Config warning: ignoring unknown setopt '",kword,"'.");
762  warn = true;
763  return true;
764 }
765 
766 /******************************************************************************/
767 
768 void XrdOucPsx::ParseSet(const char *kword, int kval)
769 {
770  XrdOucTList *item = new XrdOucTList(kword, kval);
771 
772  if (setLast) item->next = setLast;
773  else setFirst = item;
774  setLast = item;
775 }
776 
777 /******************************************************************************/
778 /* P a r s e T r a c e */
779 /******************************************************************************/
780 
781 /* Function: ParseTrace
782 
783  Purpose: To parse the directive: trace <events>
784 
785  <events> the blank separated list of events to trace. Trace
786  directives are cummalative.
787 
788  Output: true upon success or false upon failure.
789 */
790 
792 {
793  char *val;
794  static struct traceopts {const char *opname; int opval;} tropts[] =
795  {
796  {"all", 3},
797  {"debug", 2},
798  {"on", 1}
799  };
800  int i, trval = 0, numopts = sizeof(tropts)/sizeof(struct traceopts);
801 
802  if (!(val = Config.GetWord()))
803  {Eroute->Emsg("Config", "trace option not specified"); return false;}
804  while (val)
805  {if (!strcmp(val, "off")) trval = 0;
806  else {for (i = 0; i < numopts; i++)
807  {if (!strcmp(val, tropts[i].opname))
808  {trval |= tropts[i].opval;
809  break;
810  }
811  }
812  if (i >= numopts)
813  {Eroute->Say("Config warning: ignoring invalid trace option '",val,"'.");
814  warn = true;
815  }
816  }
817  val = Config.GetWord();
818  }
819  traceLvl = trval;
820  return true;
821 }
822 
823 /******************************************************************************/
824 /* S e t R o o t */
825 /******************************************************************************/
826 
827 void XrdOucPsx::SetRoot(const char *lroot, const char *rroot)
828 {
829 // Handle the local root (posix dependent)
830 //
831  if (LocalRoot) free(LocalRoot);
832  if (!lroot) LocalRoot = 0;
833  {LocalRoot = strdup(lroot);
834  xLfn2Pfn = true;
835  }
836 
837 // Handle the oss local root
838 //
839  if (RemotRoot) free(RemotRoot);
840  RemotRoot = (rroot ? strdup(rroot) : 0);
841 }
842 
843 /******************************************************************************/
844 /* Private: W a r n C o n f i g */
845 /******************************************************************************/
846 
847 void XrdOucPsx::WarnConfig(XrdSysError &eDest, XrdOucTList *tList, bool fatal)
848 {
849 
850 // Indicate we have a problem
851 //
852  eDest.Say("\n--------------");
853 
854  eDest.Say("Config problem: ",(fatal ? "fatal ":0),"errors in config file '",
855  configFN, "'; details below.\n");
856 
857 // Now dump the whole thing
858 //
859  while(tList)
860  {eDest.Say(tList->text);
861  tList = tList->next;
862  }
863  eDest.Say("--------------\n");
864 }
865 
866 /******************************************************************************/
867 /* Private: W a r n P l u g i n */
868 /******************************************************************************/
869 
870 void XrdOucPsx::WarnPlugin(XrdSysError &eDest, XrdOucTList *tList,
871  const char *txt1, const char *txt2)
872 {
873 
874 // Indicate we have a problem
875 //
876  eDest.Say("\n--------------");
877 
878  eDest.Say("Config problem: unable to load ", txt1, " ", txt2,
879  "'; details below.\n");
880 
881 // Now dump the whole thing
882 //
883  while(tList)
884  {eDest.Say(tList->text);
885  tList = tList->next;
886  }
887  eDest.Say("--------------\n");
888 }
static XrdSysError eDest(0,"crypto_")
bool(* XrdOucCacheCMInit_t)(XrdPosixCache &Cache, XrdSysLogger *Logger, const char *Config, const char *Parms, XrdOucEnv *envP)
XrdOucCache *(* XrdOucCache_t)(XrdSysLogger *Logger, const char *Config, const char *Parms, XrdOucEnv *envP)
Definition: XrdOucCache.hh:765
#define TS_Xeq(x, m)
Definition: XrdOucPsx.cc:62
int open(const char *path, int oflag,...)
size_t strlcpy(char *dst, const char *src, size_t sz)
static int Export(const char *Var, const char *Val)
Definition: XrdOucEnv.cc:188
static const int xP2Lon
Definition: XrdOucPsx.hh:98
XrdOucEnv * theEnv
Definition: XrdOucPsx.hh:80
bool useV4
Definition: XrdOucPsx.hh:92
bool ParseINet(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:611
static const int xP2Lsgi
Definition: XrdOucPsx.hh:100
bool ClientConfig(const char *pfx, bool hush=false)
Definition: XrdOucPsx.cc:100
char * configFN
Definition: XrdOucPsx.hh:78
bool ParseCio(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:481
char * mCache
Definition: XrdOucPsx.hh:84
int traceLvl
Definition: XrdOucPsx.hh:88
int cioTries
Definition: XrdOucPsx.hh:91
void SetRoot(const char *lroot, const char *oroot=0)
Definition: XrdOucPsx.cc:827
bool ParseMLib(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:571
char xPfn2Lfn
Definition: XrdOucPsx.hh:94
XrdOucCache * theCache
Definition: XrdOucPsx.hh:82
int cioWait
Definition: XrdOucPsx.hh:90
XrdOucTList * setFirst
Definition: XrdOucPsx.hh:85
bool xNameLib
Definition: XrdOucPsx.hh:95
static const int xP2Lsrc
Definition: XrdOucPsx.hh:99
int debugLvl
Definition: XrdOucPsx.hh:89
bool xLfn2Pfn
Definition: XrdOucPsx.hh:93
bool ParseCache(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:330
XrdOucName2Name * theN2N
Definition: XrdOucPsx.hh:81
XrdOucCacheCMInit_t initCCM
Definition: XrdOucPsx.hh:83
static const int xP2Loff
Definition: XrdOucPsx.hh:97
XrdOucTList * setLast
Definition: XrdOucPsx.hh:86
bool ParseCLib(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:525
bool ConfigSetup(XrdSysError &eDest, bool hush=false)
Definition: XrdOucPsx.cc:217
bool ParseNLib(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:646
~XrdOucPsx()
Definition: XrdOucPsx.cc:78
bool ParseTrace(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:791
bool ParseSet(XrdSysError *Eroute, XrdOucStream &Config)
Definition: XrdOucPsx.cc:702
XrdOucTList * first
Definition: XrdOucTList.hh:102
XrdOucTList * next
Definition: XrdOucTList.hh:45
char * text
Definition: XrdOucTList.hh:46
static int a2i(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
Definition: XrdOuca2x.cc:45
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
Definition: XrdOuca2x.cc:257
static int a2tm(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
Definition: XrdOuca2x.cc:288
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
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)
Definition: XrdSysError.cc:141
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
void Capture(XrdOucTListFIFO *tFIFO)
XrdCmsConfig Config