-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdTpcConfigure.cc
182 lines (169 loc) · 6.79 KB
/
XrdTpcConfigure.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "XrdTpcTPC.hh"
#include <dlfcn.h>
#include <fcntl.h>
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucPinPath.hh"
#include "XrdSfs/XrdSfsInterface.hh"
extern XrdSfsFileSystem *XrdSfsGetDefaultFileSystem(XrdSfsFileSystem *native_fs,
XrdSysLogger *lp,
const char *configfn,
XrdOucEnv *EnvInfo);
using namespace TPC;
static XrdSfsFileSystem *load_sfs(void *handle, bool alt, XrdSysError &log, const std::string &libpath, const char *configfn, XrdOucEnv &myEnv, XrdSfsFileSystem *prior_sfs) {
XrdSfsFileSystem *sfs = NULL;
if (alt) {
XrdSfsFileSystem2_t ep = (XrdSfsFileSystem *(*)(XrdSfsFileSystem *, XrdSysLogger *, const char *, XrdOucEnv *))
(dlsym(handle, "XrdSfsGetFileSystem2"));
if (ep == NULL) {
log.Emsg("Config", "Failed to load XrdSfsGetFileSystem2 from library ", libpath.c_str(), dlerror());
return NULL;
}
sfs = ep(prior_sfs, log.logger(), configfn, &myEnv);
} else {
XrdSfsFileSystem_t ep = (XrdSfsFileSystem *(*)(XrdSfsFileSystem *, XrdSysLogger *, const char *))
(dlsym(NULL, "XrdSfsGetFileSystem"));
if (ep == NULL) {
log.Emsg("Config", "Failed to load XrdSfsGetFileSystem from library ", libpath.c_str(), dlerror());
return NULL;
}
sfs = ep(prior_sfs, log.logger(), configfn);
}
if (!sfs) {
log.Emsg("Config", "Failed to initialize filesystem library for TPC handler from ", libpath.c_str());
return NULL;
}
return sfs;
}
bool TPCHandler::ConfigureFSLib(XrdOucStream &Config, std::string &path1, bool &path1_alt, std::string &path2, bool &path2_alt) {
char *val;
if (!(val = Config.GetWord())) {
m_log.Emsg("Config", "fslib not specified");
return false;
}
if (!strcmp("throttle", val)) {
path2 = "libXrdThrottle.so";
if (!(val = Config.GetWord())) {
m_log.Emsg("Config", "fslib throttle target library not specified");
return false;
}
}
else if (!strcmp("-2", val)) {
path2_alt = true;
if (!(val = Config.GetWord())) {
m_log.Emsg("Config", "fslib library not specified");
return false;
}
path2 = val;
}
else {
path2 = val;
}
if (!(val = Config.GetWord()) || !strcmp("default", val)) {
if (path2 == "libXrdThrottle.so") {
path1 = "default";
} else if (!path2.empty()) {
path1 = path2;
path2 = "";
path1_alt = path2_alt;
}
} else if (!strcmp("-2", val)) {
path1_alt = true;
if (!(val = Config.GetWord())) {
m_log.Emsg("Config", "fslib base library not specified");
return false;
}
path1 = val;
} else {
path2 = val;
}
return true;
}
bool TPCHandler::Configure(const char *configfn, XrdOucEnv *myEnv)
{
XrdOucStream Config(&m_log, getenv("XRDINSTANCE"), myEnv, "=====> ");
std::string authLib;
std::string authLibParms;
int cfgFD = open(configfn, O_RDONLY, 0);
if (cfgFD < 0) {
m_log.Emsg("Config", errno, "open config file", configfn);
return false;
}
Config.Attach(cfgFD);
const char *val;
std::string path2, path1 = "default";
bool path1_alt = false, path2_alt = false;
while ((val = Config.GetMyFirstWord())) {
if (!strcmp("xrootd.fslib", val)) {
if (!ConfigureFSLib(Config, path1, path1_alt, path2, path2_alt)) {
Config.Close();
m_log.Emsg("Config", "Failed to parse the xrootd.fslib directive");
return false;
}
m_log.Emsg("Config", "xrootd.fslib line successfully processed by TPC handler/");
} else if (!strcmp("http.desthttps", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
m_log.Emsg("Config", "http.desthttps value not specified");
return false;
}
if (!strcmp("1", val) || !strcasecmp("yes", val) || !strcasecmp("true", val)) {
m_desthttps = true;
} else if (!strcmp("0", val) || !strcasecmp("no", val) || !strcasecmp("false", val)) {
m_desthttps = false;
} else {
Config.Close();
m_log.Emsg("Config", "https.desthttps value is invalid", val);
return false;
}
} else if (!strcmp("http.cadir", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
m_log.Emsg("Config", "http.cadir value not specified");
return false;
}
m_cadir = val;
}
}
Config.Close();
XrdSfsFileSystem *base_sfs = NULL;
if (path1 == "default") {
m_log.Emsg("Config", "Loading the default filesystem");
base_sfs = XrdSfsGetDefaultFileSystem(NULL, m_log.logger(), configfn, myEnv);
m_log.Emsg("Config", "Finished loading the default filesystem");
} else {
char resolvePath[2048];
bool usedAltPath{true};
if (!XrdOucPinPath(path1.c_str(), usedAltPath, resolvePath, 2048)) {
m_log.Emsg("Config", "Failed to locate appropriately versioned base filesystem library for ", path1.c_str());
return false;
}
m_handle_base = dlopen(resolvePath, RTLD_LOCAL|RTLD_NOW);
if (m_handle_base == NULL) {
m_log.Emsg("Config", "Failed to base plugin ", resolvePath, dlerror());
return false;
}
base_sfs = load_sfs(m_handle_base, path1_alt, m_log, path1, configfn, *myEnv, NULL);
}
if (!base_sfs) {
m_log.Emsg("Config", "Failed to initialize filesystem library for TPC handler from ", path1.c_str());
return false;
}
XrdSfsFileSystem *chained_sfs = NULL;
if (!path2.empty()) {
char resolvePath[2048];
bool usedAltPath{true};
if (!XrdOucPinPath(path2.c_str(), usedAltPath, resolvePath, 2048)) {
m_log.Emsg("Config", "Failed to locate appropriately versioned chained filesystem library for ", path2.c_str());
return false;
}
m_handle_chained = dlopen(resolvePath, RTLD_LOCAL|RTLD_NOW);
if (m_handle_chained == NULL) {
m_log.Emsg("Config", "Failed to chained plugin ", resolvePath, dlerror());
return false;
}
chained_sfs = load_sfs(m_handle_chained, path2_alt, m_log, path2, configfn, *myEnv, base_sfs);
}
m_sfs.reset(chained_sfs ? chained_sfs : base_sfs);
m_log.Emsg("Config", "Successfully configured the filesystem object for TPC handler");
return true;
}