-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ntpl] Allow XRootD redirection with EOS files #20272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vepadulano
wants to merge
1
commit into
root-project:master
Choose a base branch
from
vepadulano:rntuple-eos-xrootd-redirection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /************************************************************************* | ||
| * Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. * | ||
| * All rights reserved. * | ||
| * * | ||
| * For the licensing terms see $ROOTSYS/LICENSE. * | ||
| * For the list of contributors see $ROOTSYS/README/CREDITS. * | ||
| *************************************************************************/ | ||
|
|
||
| // Author: Vincenzo Eduardo Padulano (CERN), 11/2025 | ||
|
|
||
| #ifndef ROOT_IO_UTILS | ||
| #define ROOT_IO_UTILS | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| namespace ROOT::Internal { | ||
|
|
||
| /// \brief Get extended attribute value from path | ||
| /// \param path Path to the file to check | ||
| /// \param xattr Extended attribute to evaluate | ||
| /// \return The string containing the extended attribute value if found, std::nullopt otherwise | ||
| std::optional<std::string> GetXAttrVal(const char *path, const char *xattr); | ||
|
|
||
| /// \brief Redirects the input URL to the equivalent XRootD path on EOS | ||
| /// \param inputUrl The input URL to redirect | ||
| /// \return The redirected URL in case of successful redirection, std::nullopt otherwise | ||
| std::optional<std::string> GetEOSRedirectedXRootURL(const char *inputURL); | ||
| } // namespace ROOT::Internal | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #include "ROOT/InternalIOUtils.hxx" | ||
|
|
||
| #include "ROOT/RConfig.hxx" // R__UNIX | ||
|
|
||
| #ifdef R__UNIX | ||
| // getxattr | ||
| #ifdef R__FBSD | ||
| #include <sys/extattr.h> | ||
| #else | ||
| #include <sys/xattr.h> | ||
| #endif | ||
|
|
||
| #ifdef R__MACOSX | ||
| /* On macOS getxattr takes two extra arguments that should be set to 0 */ | ||
| #define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0) | ||
| #endif | ||
|
|
||
| #ifdef R__FBSD | ||
| #define getxattr(path, name, value, size) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size) | ||
| #endif | ||
|
|
||
| #include "ROOT/StringUtils.hxx" // ROOT::StartsWith | ||
| #include "TEnv.h" // TEnv::GetValue | ||
| #endif | ||
|
|
||
| std::optional<std::string> ROOT::Internal::GetXAttrVal(const char *path, const char *xattr) | ||
| { | ||
| #ifdef R__UNIX | ||
| // First call to getxattr evaluates the length of the extended attribute value | ||
| if (auto len = getxattr(path, xattr, nullptr, 0); len > 0) { | ||
| std::string xval(len, 0); | ||
| // Second call extracts the extended attribute value, checking it's of the correct length | ||
| if (getxattr(path, xattr, xval.data(), len) == len) | ||
| return xval; | ||
| } | ||
| #else | ||
| (void)path; | ||
| (void)xattr; | ||
| #endif | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::optional<std::string> ROOT::Internal::GetEOSRedirectedXRootURL(const char *inputURL) | ||
| { | ||
| #ifdef R__UNIX | ||
| if (!inputURL) | ||
| return std::nullopt; | ||
|
|
||
| std::string_view inputSV{inputURL}; | ||
| if (inputSV.empty() || inputSV.back() == '/') | ||
| return std::nullopt; | ||
|
|
||
| if (gEnv->GetValue("TFile.CrossProtocolRedirects", 1) != 1) | ||
| return std::nullopt; | ||
|
|
||
| auto xurl = ROOT::Internal::GetXAttrVal(inputURL, "eos.url.xroot"); | ||
| if (!xurl) | ||
| return std::nullopt; | ||
|
|
||
| auto baseName = inputSV.substr(inputSV.find_last_of("/") + 1); | ||
| // Sometimes the `getxattr` call may return an invalid URL due | ||
| // to the POSIX attribute not being yet completely filled by EOS. | ||
| if (!std::equal(baseName.crbegin(), baseName.crend(), xurl->crbegin())) | ||
| return std::nullopt; | ||
|
|
||
| // Ensure the redirected URL actually starts with the XRootD protocol string | ||
| if (ROOT::StartsWith(*xurl, "root://") || ROOT::StartsWith(*xurl, "xroot://") || | ||
| ROOT::StartsWith(*xurl, "roots://") || ROOT::StartsWith(*xurl, "xroots://")) | ||
| return xurl; | ||
| #else | ||
| (void)inputURL; | ||
| #endif | ||
| return std::nullopt; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.