XRootD
XrdClS3::Filesystem Class Referencefinal

#include <XrdClS3Filesystem.hh>

+ Inheritance diagram for XrdClS3::Filesystem:
+ Collaboration diagram for XrdClS3::Filesystem:

Public Member Functions

 Filesystem (const std::string &, XrdCl::Log *log)
 
virtual ~Filesystem () noexcept
 
virtual XrdCl::XRootDStatus DirList (const std::string &path, XrdCl::DirListFlags::Flags flags, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual bool GetProperty (const std::string &name, std::string &value) const override
 
virtual XrdCl::XRootDStatus Locate (const std::string &path, XrdCl::OpenFlags::Flags flags, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus MkDir (const std::string &path, XrdCl::MkDirFlags::Flags flags, XrdCl::Access::Mode mode, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus Query (XrdCl::QueryCode::Code queryCode, const XrdCl::Buffer &arg, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus Rm (const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus RmDir (const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual bool SetProperty (const std::string &name, const std::string &value) override
 
virtual XrdCl::XRootDStatus Stat (const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
 
- Public Member Functions inherited from XrdCl::FileSystemPlugIn
virtual ~FileSystemPlugIn ()
 Destructor. More...
 
virtual XRootDStatus ChMod (const std::string &path, Access::Mode mode, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus DeepLocate (const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus DelXAttr (const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus GetXAttr (const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus ListXAttr (const std::string &path, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Mv (const std::string &source, const std::string &dest, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Ping (ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Prepare (const std::vector< std::string > &fileList, PrepareFlags::Flags flags, uint8_t priority, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Protocol (ResponseHandler *handler, time_t timeout=0)
 
virtual XRootDStatus SendInfo (const std::string &info, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus SetXAttr (const std::string &path, const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus StatVFS (const std::string &path, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Truncate (const std::string &path, uint64_t size, ResponseHandler *handler, time_t timeout)
 

Detailed Description

Definition at line 41 of file XrdClS3Filesystem.hh.

Constructor & Destructor Documentation

◆ Filesystem()

Filesystem::Filesystem ( const std::string &  url,
XrdCl::Log *  log 
)

Definition at line 443 of file XrdClS3Filesystem.cc.

443  :
444  m_logger(log),
445  m_url(url)
446 {
447  m_url.SetPath("");
449  m_url.SetParams(map);
450 
451  m_logger->Debug(kLogXrdClS3, "S3 filesystem constructed with URL: %s.",
452  m_url.GetURL().c_str());
453 }
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
void SetParams(const std::string &params)
Set params.
Definition: XrdClURL.cc:378
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:225
const uint64_t kLogXrdClS3

References XrdCl::Log::Debug(), XrdCl::URL::GetURL(), XrdClS3::kLogXrdClS3, XrdCl::URL::SetParams(), and XrdCl::URL::SetPath().

+ Here is the call graph for this function:

◆ ~Filesystem()

Filesystem::~Filesystem ( )
virtualnoexcept

Definition at line 455 of file XrdClS3Filesystem.cc.

455 {}

Member Function Documentation

◆ DirList()

XrdCl::XRootDStatus Filesystem::DirList ( const std::string &  path,
XrdCl::DirListFlags::Flags  flags,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::DirlList

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 458 of file XrdClS3Filesystem.cc.

462 {
463  std::string https_url, err_msg;
464  const auto s3_url = XrdOucUtils::JoinUrl(m_url.GetURL(), path);
465  std::string obj;
466  if (!Factory::GenerateHttpUrl(s3_url, https_url, &obj, err_msg)) {
468  }
469  obj = obj.substr(0, obj.find('?'));
470  auto query_loc = https_url.find('?');
471  https_url += (query_loc == std::string::npos) ? "?" : "&";
472  https_url += "list-type=2&delimiter=/&encoding-type=url";
473  https_url += "&prefix=" + urlquote(obj) + "/";
474 
475  auto expiry = time(NULL) + timeout;
476 
477  return DownloadUrl(
478  https_url,
479  &m_header_callout,
480  new DirListResponseHandler(
481  false, https_url, &m_header_callout, handler, expiry, *m_logger
482  ),
483  timeout
484  );
485 }
static bool GenerateHttpUrl(const std::string &s3_url, std::string &https_url, std::string *obj_result, std::string &err_msg)
static std::string JoinUrl(const std::string &base, const std::string &path)
XrdCl::XRootDStatus DownloadUrl(const std::string &url, XrdClHttp::HeaderCallout *header_callout, XrdCl::ResponseHandler *handler, time_t timeout)
const uint16_t errInvalidAddr
Definition: XrdClStatus.hh:71
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32

References XrdClS3::DownloadUrl(), XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), XrdCl::URL::GetURL(), XrdOucUtils::JoinUrl(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ GetProperty()

bool Filesystem::GetProperty ( const std::string &  name,
std::string &  value 
) const
overridevirtual
See also
XrdCl::FileSystem::GetProperty

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 528 of file XrdClS3Filesystem.cc.

530 {
531  std::unique_lock lock(m_properties_mutex);
532  const auto p = m_properties.find(name);
533  if (p == std::end(m_properties)) {
534  return false;
535  }
536 
537  value = p->second;
538  return true;
539 }

◆ Locate()

XrdCl::XRootDStatus Filesystem::Locate ( const std::string &  path,
XrdCl::OpenFlags::Flags  flags,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Locate

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 542 of file XrdClS3Filesystem.cc.

546 {
547  auto cleaned_path = Factory::CleanObjectName(path);
548  auto [st, fs] = GetFSHandle(cleaned_path);
549  if (!st.IsOK()) {
550  return st;
551  }
552  return fs->Locate(cleaned_path, flags, handler, timeout);
553 }
static std::string CleanObjectName(const std::string &object)

References XrdClS3::Factory::CleanObjectName().

+ Here is the call graph for this function:

◆ MkDir()

XrdCl::XRootDStatus Filesystem::MkDir ( const std::string &  path,
XrdCl::MkDirFlags::Flags  flags,
XrdCl::Access::Mode  mode,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::MkDir

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 556 of file XrdClS3Filesystem.cc.

561 {
562  auto sentinel = Factory::GetMkdirSentinel();
563  if (sentinel.empty()) {
564  if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
565  return {};
566  }
567  auto loc = input_path.find('?');
568  auto path = input_path.substr(0, loc);
569  if (!path.empty() && path[path.size() - 1] != '/') path += "/";
570  path += sentinel;
571  if (loc != std::string::npos) {
572  path += input_path.substr(loc);
573  }
574 
575  // Try creating a zero-sized sentinel.
576  std::string https_url, err_msg;
577  const auto s3_url = XrdOucUtils::JoinUrl(m_url.GetURL(), path);
578  if (!Factory::GenerateHttpUrl(s3_url, https_url, nullptr, err_msg)) {
580  }
581 
582  XrdCl::File *http_file(new XrdCl::File(https_url));
583 
584  auto callout_loc = reinterpret_cast<long long>(&m_header_callout);
585  size_t buf_size = 16;
586  char callout_buf[buf_size];
587  std::to_chars_result result = std::to_chars(callout_buf, callout_buf + buf_size - 1, callout_loc, 16);
588  if (result.ec == std::errc{}) {
589  std::string callout_str(callout_buf, result.ptr - callout_buf);
590  http_file->SetProperty("XrdClHttpHeaderCallout", callout_str);
591  }
592 
593  MkdirHandler *mkdirHandler = new MkdirHandler(http_file, handler, timeout);
594 
595  return http_file->Open(https_url, XrdCl::OpenFlags::Write, XrdCl::Access::None, mkdirHandler, timeout);
596 }
static const std::string & GetMkdirSentinel()
A file.
Definition: XrdClFile.hh:52
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
@ Write
Open only for writing.

References XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), XrdClS3::Factory::GetMkdirSentinel(), XrdCl::URL::GetURL(), XrdCl::ResponseHandler::HandleResponse(), XrdOucUtils::JoinUrl(), XrdCl::Access::None, XrdCl::File::Open(), XrdCl::File::SetProperty(), XrdCl::stError, and XrdCl::OpenFlags::Write.

+ Here is the call graph for this function:

◆ Query()

XrdCl::XRootDStatus Filesystem::Query ( XrdCl::QueryCode::Code  queryCode,
const XrdCl::Buffer &  arg,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Query

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 599 of file XrdClS3Filesystem.cc.

603 {
604  if (queryCode != XrdCl::QueryCode::Checksum && queryCode != XrdCl::QueryCode::XAttr) {
606  }
607  auto cleaned_path = Factory::CleanObjectName(arg.ToString());
608  auto [st, fs] = GetFSHandle(cleaned_path);
609  if (!st.IsOK()) {
610  return st;
611  }
612  XrdCl::Buffer cleanedArg;
613  cleanedArg.FromString(cleaned_path);
614  return fs->Query(queryCode, cleanedArg, handler, timeout);
615 }
Binary blob representation.
Definition: XrdClBuffer.hh:34
void FromString(const std::string str)
Fill the buffer from a string.
Definition: XrdClBuffer.hh:205
std::string ToString() const
Convert the buffer to a string.
Definition: XrdClBuffer.hh:215
const uint16_t errNotImplemented
Operation is not implemented.
Definition: XrdClStatus.hh:64
@ XAttr
Query file extended attributes.
@ Checksum
Query file checksum.

References XrdCl::QueryCode::Checksum, XrdClS3::Factory::CleanObjectName(), XrdCl::errNotImplemented, XrdCl::Buffer::FromString(), XrdCl::stError, XrdCl::Buffer::ToString(), and XrdCl::QueryCode::XAttr.

+ Here is the call graph for this function:

◆ Rm()

XrdCl::XRootDStatus Filesystem::Rm ( const std::string &  path,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Rm

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 619 of file XrdClS3Filesystem.cc.

622 {
623  auto cleaned_path = Factory::CleanObjectName(path);
624  auto [st, fs] = GetFSHandle(cleaned_path);
625  if (!st.IsOK()) {
626  return st;
627  }
628  return fs->Rm(cleaned_path, handler, timeout);
629 }

References XrdClS3::Factory::CleanObjectName().

Referenced by RmDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RmDir()

XrdCl::XRootDStatus Filesystem::RmDir ( const std::string &  path,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::RmDir

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 632 of file XrdClS3Filesystem.cc.

635 {
636  auto sentinel = Factory::GetMkdirSentinel();
637  if (sentinel.empty()) {
638  if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
639  return {};
640  }
641  auto loc = input_path.find('?');
642  auto path = input_path.substr(0, loc);
643  if (!path.empty() && path[path.size() - 1] != '/') path += "/";
644  path += sentinel;
645  if (loc != std::string::npos) {
646  path += input_path.substr(loc);
647  }
648  return Rm(path, handler, timeout);
649 }
virtual XrdCl::XRootDStatus Rm(const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override

References XrdClS3::Factory::GetMkdirSentinel(), XrdCl::ResponseHandler::HandleResponse(), and Rm().

+ Here is the call graph for this function:

◆ SetProperty()

bool Filesystem::SetProperty ( const std::string &  name,
const std::string &  value 
)
overridevirtual
See also
XrdCl::FileSystem::SetProperty

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 653 of file XrdClS3Filesystem.cc.

655 {
656  std::unique_lock lock(m_properties_mutex);
657  m_properties[name] = value;
658  return true;
659 }

◆ Stat()

XrdCl::XRootDStatus Filesystem::Stat ( const std::string &  path,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Stat

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 662 of file XrdClS3Filesystem.cc.

665 {
666  auto cleaned_path = Factory::CleanObjectName(path);
667  auto [st, fs] = GetFSHandle(cleaned_path);
668  if (!st.IsOK()) {
669  return st;
670  }
671  return fs->Stat(cleaned_path, new StatHandler(cleaned_path, m_url.GetURL(), &m_header_callout, handler, timeout, *m_logger), timeout);
672 }

References XrdClS3::Factory::CleanObjectName(), and XrdCl::URL::GetURL().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: