Skip to content

Commit 3e7059b

Browse files
committed
[ntpl] Allow XRootD redirection with EOS files
1 parent 56be091 commit 3e7059b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

io/io/src/RRawFile.cxx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@
2121
#include "TPluginManager.h"
2222
#include "TROOT.h"
2323

24+
// XRootD protocol redirection
25+
#ifdef R__UNIX
26+
27+
#ifdef R__FBSD
28+
#include <sys/extattr.h>
29+
#else
30+
#include <sys/xattr.h>
31+
#endif
32+
33+
#ifdef R__MACOSX
34+
/* On macOS getxattr takes two extra arguments that should be set to 0 */
35+
#define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0)
36+
#endif
37+
38+
#ifdef R__FBSD
39+
#define getxattr(path, name, value, size) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size)
40+
#endif
41+
42+
#include "TEnv.h"
43+
44+
#endif
45+
2446
#include <algorithm>
2547
#include <cctype> // for towlower
2648
#include <cerrno>
@@ -68,6 +90,23 @@ ROOT::Internal::RRawFile::Create(std::string_view url, ROptions options)
6890
#ifdef _WIN32
6991
return std::unique_ptr<RRawFile>(new RRawFileWin(url, options));
7092
#else
93+
// If URL is a file on an EOS FUSE mount, attempt redirection to XRootD protocol.
94+
if (gEnv->GetValue("TFile.CrossProtocolRedirects", 1) == 1) {
95+
// At the moment the url parameter can only be the file name
96+
ssize_t len = getxattr(url.data(), "eos.url.xroot", nullptr, 0);
97+
if (len > 0) {
98+
std::string xurl(len, 0);
99+
std::string fileNameFromUrl{url.data()};
100+
if (getxattr(fileNameFromUrl.c_str(), "eos.url.xroot", &xurl[0], len) == len) {
101+
// Sometimes the `getxattr` call may return an invalid URL due
102+
// to the POSIX attribute not being yet completely filled by EOS.
103+
if (auto baseName = fileNameFromUrl.substr(fileNameFromUrl.find_last_of("/") + 1);
104+
std::equal(baseName.crbegin(), baseName.crend(), xurl.crbegin())) {
105+
return Create(xurl, options);
106+
}
107+
}
108+
}
109+
}
71110
return std::unique_ptr<RRawFile>(new RRawFileUnix(url, options));
72111
#endif
73112
}

0 commit comments

Comments
 (0)