XRootD
Loading...
Searching...
No Matches
XrdOssCsiConfig.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O s s C s i C o n f i g . c c */
4/* */
5/* (C) Copyright 2021 CERN. */
6/* */
7/* This file is part of the XRootD software suite. */
8/* */
9/* XRootD is free software: you can redistribute it and/or modify it under */
10/* the terms of the GNU Lesser General Public License as published by the */
11/* Free Software Foundation, either version 3 of the License, or (at your */
12/* option) any later version. */
13/* */
14/* In applying this licence, CERN does not waive the privileges and */
15/* immunities granted to it by virtue of its status as an Intergovernmental */
16/* Organization or submit itself to any jurisdiction. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include "XrdOssCsiConfig.hh"
33#include "XrdOss/XrdOss.hh"
34#include "XrdOssCsiTrace.hh"
35
36#include <sys/types.h>
37#include <sys/stat.h>
38#include <fcntl.h>
39
40#include <sstream>
41#include <string>
42#include <vector>
43
45
46#define TS_Xeq(x,m) if (!strcmp(x,var)) return m(Config, Eroute);
47
48int XrdOssCsiConfig::Init(XrdSysError &Eroute, const char *config_fn, const char *parms, XrdOucEnv * /* envP */)
49{
50 int NoGo = XrdOssOK;
51 Eroute.Say("++++++ OssCsi plugin initialization started.");
52
53 std::stringstream ss(parms ? parms : "");
54 std::string item;
55
56 while(std::getline(ss, item, ' '))
57 {
58 std::string value;
59 const auto idx = item.find('=');
60 if (idx != std::string::npos)
61 {
62 value = item.substr(idx+1, std::string::npos);
63 item.erase(idx, std::string::npos);
64 }
65 if (item == "nofill")
66 {
67 fillFileHole_ = false;
68 }
69 else if (item == "space" && !value.empty())
70 {
71 xrdtSpaceName_ = value;
72 }
73 else if (item == "nomissing")
74 {
75 allowMissingTags_ = false;
76 }
77 else if (item == "prefix")
78 {
79 if (tagParam_.SetPrefix(Eroute, value)) NoGo = 1;
80 }
81 else if (item == "nopgextend")
82 {
83 disablePgExtend_ = true;
84 }
85 else if (item == "noloosewrites")
86 {
87 disableLooseWrite_ = true;
88 }
89 }
90
91 if (NoGo) return NoGo;
92
94 if (getenv("XRDDEBUG")) OssCsiTrace.What = TRACE_ALL;
95 if (readConfig(Eroute, config_fn)) return 1;
96
97 Eroute.Say(" compute file holes : ", fillFileHole_ ? "yes" : "no");
98 Eroute.Say(" space name : ", xrdtSpaceName_.c_str());
99 Eroute.Say(" allow files without CRCs: ", allowMissingTags_ ? "yes" : "no");
100 Eroute.Say(" pgWrite can extend : ", disablePgExtend_ ? "no" : "yes");
101 Eroute.Say(" loose writes : ", disableLooseWrite_ ? "no" : "yes");
102 Eroute.Say(" trace level : ", std::to_string((long long int)OssCsiTrace.What).c_str());
103 Eroute.Say(" prefix : ", tagParam_.prefix_.empty() ? "[empty]" : tagParam_.prefix_.c_str());
104
105 Eroute.Say("++++++ OssCsi plugin initialization completed.");
106
107
108 return XrdOssOK;
109}
110
111int XrdOssCsiConfig::readConfig(XrdSysError &Eroute, const char *ConfigFN)
112{
113 char *var;
114 int cfgFD, retc, NoGo = XrdOssOK;
115 XrdOucEnv myEnv;
116 XrdOucStream Config(&Eroute, getenv("XRDINSTANCE"), &myEnv, "=====> ");
117
118 if( !ConfigFN || !*ConfigFN)
119 {
120 Eroute.Say("Config warning: config file not specified; defaults assumed.");
121 return XrdOssOK;
122 }
123
124 if ( (cfgFD = open(ConfigFN, O_RDONLY, 0)) < 0)
125 {
126 Eroute.Emsg("Config", errno, "open config file", ConfigFN);
127 return 1;
128 }
129
130 Config.Attach(cfgFD);
131 static const char *cvec[] = { "*** osscsi plugin config:", 0 };
132 Config.Capture(cvec);
133
134 while((var = Config.GetMyFirstWord()))
135 {
136 if (!strncmp(var, "csi.", 4))
137 {
138 if (ConfigXeq(var+4, Config, Eroute))
139 {
140 Config.Echo(); NoGo = 1;
141 }
142 }
143 }
144
145 if ((retc = Config.LastError()))
146 NoGo = Eroute.Emsg("Config", retc, "read config file", ConfigFN);
147
148 Config.Close();
149
150 return NoGo;
151}
152
153int XrdOssCsiConfig::ConfigXeq(char *var, XrdOucStream &Config, XrdSysError &Eroute)
154{
155 TS_Xeq("trace", xtrace);
156 return 0;
157}
158
159int XrdOssCsiConfig::xtrace(XrdOucStream &Config, XrdSysError &Eroute)
160{
161 char *val;
162 static struct traceopts {const char *opname; int opval;} tropts[] =
163 {
164 {"all", TRACE_ALL},
165 {"debug", TRACE_Debug},
166 {"warn", TRACE_Warn},
167 {"info", TRACE_Info}
168 };
169 int i, neg, trval = 0, numopts = sizeof(tropts)/sizeof(struct traceopts);
170
171 if (!(val = Config.GetWord()))
172 {Eroute.Emsg("Config", "trace option not specified"); return 1;}
173 while (val)
174 {if (!strcmp(val, "off")) trval = 0;
175 else {if ((neg = (val[0] == '-' && val[1]))) val++;
176 for (i = 0; i < numopts; i++)
177 {if (!strcmp(val, tropts[i].opname))
178 {if (neg) trval &= ~tropts[i].opval;
179 else trval |= tropts[i].opval;
180 break;
181 }
182 }
183 if (i >= numopts)
184 Eroute.Say("Config warning: ignoring invalid trace option '",val,"'.");
185 }
186 val = Config.GetWord();
187 }
188 OssCsiTrace.What = trval;
189 return 0;
190}
#define TRACE_Debug
#define TS_Xeq(x, m)
Definition XrdConfig.cc:156
XrdOucTrace OssCsiTrace
#define TRACE_Warn
#define TRACE_Info
#define XrdOssOK
Definition XrdOss.hh:50
#define open
Definition XrdPosix.hh:71
#define TRACE_ALL
Definition XrdTrace.hh:35
int Init(XrdSysError &, const char *, const char *, XrdOucEnv *)
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)
XrdCmsConfig Config