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 495 of file XrdClS3Filesystem.cc.

495  :
496  m_logger(log),
497  m_url(url)
498 {
499  m_url.SetPath("");
501  m_url.SetParams(map);
502 
503  m_logger->Debug(kLogXrdClS3, "S3 filesystem constructed with URL: %s.",
504  m_url.GetURL().c_str());
505 }
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 507 of file XrdClS3Filesystem.cc.

507 {}

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 510 of file XrdClS3Filesystem.cc.

514 {
515  std::string https_url, err_msg;
516  const auto s3_url = XrdOucUtils::JoinUrl(m_url.GetURL(), path);
517  std::string obj;
518  if (!Factory::GenerateHttpUrl(s3_url, https_url, &obj, err_msg)) {
520  }
521  obj = obj.substr(0, obj.find('?'));
522  if (!obj.empty() && obj.back() != '/') {
523  obj += "/";
524  }
525  auto query_loc = https_url.find('?');
526  https_url += (query_loc == std::string::npos) ? "?" : "&";
527  https_url += "list-type=2&delimiter=/&encoding-type=url";
528  // An empty prefix= is dropped from the signature and the request is rejected.
529  if (!obj.empty()) {
530  https_url += "&prefix=" + urlquote(obj);
531  }
532 
533  // File::Open turns a zero timeout into RequestTimeout for the first page.
534  // The next page is fetched only while this deadline is still ahead, and
535  // a zero timeout makes that deadline the current time.
536  if (!timeout) {
538  XrdCl::DefaultEnv::GetEnv()->GetInt("RequestTimeout", val);
539  timeout = val;
540  }
541  auto expiry = time(NULL) + timeout;
542 
543  return DownloadUrl(
544  https_url,
545  &m_header_callout,
546  new DirListResponseHandler(
547  false, https_url, obj, &m_header_callout, handler, expiry, *m_logger
548  ),
549  timeout
550  );
551 }
static bool GenerateHttpUrl(const std::string &s3_url, std::string &https_url, std::string *obj_result, std::string &err_msg)
static Env * GetEnv()
Get default client environment.
bool GetInt(const std::string &key, int &value)
Definition: XrdClEnv.cc:115
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
const int DefaultRequestTimeout

References XrdCl::DefaultRequestTimeout, XrdClS3::DownloadUrl(), XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), 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 594 of file XrdClS3Filesystem.cc.

596 {
597  std::unique_lock lock(m_properties_mutex);
598  const auto p = m_properties.find(name);
599  if (p == std::end(m_properties)) {
600  return false;
601  }
602 
603  value = p->second;
604  return true;
605 }

◆ 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 608 of file XrdClS3Filesystem.cc.

612 {
613  auto cleaned_path = Factory::CleanObjectName(path);
614  auto [st, fs] = GetFSHandle(cleaned_path);
615  if (!st.IsOK()) {
616  return st;
617  }
618  return fs->Locate(cleaned_path, flags, handler, timeout);
619 }
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 622 of file XrdClS3Filesystem.cc.

627 {
628  auto sentinel = Factory::GetMkdirSentinel();
629  if (sentinel.empty()) {
630  if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
631  return {};
632  }
633  auto loc = input_path.find('?');
634  auto path = input_path.substr(0, loc);
635  if (!path.empty() && path[path.size() - 1] != '/') path += "/";
636  path += sentinel;
637  if (loc != std::string::npos) {
638  path += input_path.substr(loc);
639  }
640 
641  // Try creating a zero-sized sentinel.
642  std::string https_url, err_msg;
643  const auto s3_url = XrdOucUtils::JoinUrl(m_url.GetURL(), path);
644  if (!Factory::GenerateHttpUrl(s3_url, https_url, nullptr, err_msg)) {
646  }
647 
648  XrdCl::File *http_file(new XrdCl::File(https_url));
649 
650  auto callout_loc = reinterpret_cast<long long>(&m_header_callout);
651  size_t buf_size = 16;
652  char callout_buf[buf_size];
653  std::to_chars_result result = std::to_chars(callout_buf, callout_buf + buf_size - 1, callout_loc, 16);
654  if (result.ec == std::errc{}) {
655  std::string callout_str(callout_buf, result.ptr - callout_buf);
656  http_file->SetProperty("XrdClHttpHeaderCallout", callout_str);
657  }
658 
659  MkdirHandler *mkdirHandler = new MkdirHandler(http_file, handler, timeout);
660 
661  return http_file->Open(https_url, XrdCl::OpenFlags::Write, XrdCl::Access::None, mkdirHandler, timeout);
662 }
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 665 of file XrdClS3Filesystem.cc.

669 {
670  if (queryCode != XrdCl::QueryCode::Checksum && queryCode != XrdCl::QueryCode::XAttr) {
672  }
673  auto cleaned_path = Factory::CleanObjectName(arg.ToString());
674  auto [st, fs] = GetFSHandle(cleaned_path);
675  if (!st.IsOK()) {
676  return st;
677  }
678  XrdCl::Buffer cleanedArg;
679  cleanedArg.FromString(cleaned_path);
680  return fs->Query(queryCode, cleanedArg, handler, timeout);
681 }
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 685 of file XrdClS3Filesystem.cc.

688 {
689  auto cleaned_path = Factory::CleanObjectName(path);
690  auto [st, fs] = GetFSHandle(cleaned_path);
691  if (!st.IsOK()) {
692  return st;
693  }
694  return fs->Rm(cleaned_path, handler, timeout);
695 }

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 698 of file XrdClS3Filesystem.cc.

701 {
702  auto sentinel = Factory::GetMkdirSentinel();
703  if (sentinel.empty()) {
704  if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
705  return {};
706  }
707  auto loc = input_path.find('?');
708  auto path = input_path.substr(0, loc);
709  if (!path.empty() && path[path.size() - 1] != '/') path += "/";
710  path += sentinel;
711  if (loc != std::string::npos) {
712  path += input_path.substr(loc);
713  }
714  return Rm(path, handler, timeout);
715 }
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 719 of file XrdClS3Filesystem.cc.

721 {
722  std::unique_lock lock(m_properties_mutex);
723  m_properties[name] = value;
724  return true;
725 }

◆ 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 728 of file XrdClS3Filesystem.cc.

731 {
732  auto cleaned_path = Factory::CleanObjectName(path);
733  std::string https_url, err_msg, obj;
734  const auto s3_url = XrdOucUtils::JoinUrl(m_url.GetURL(), cleaned_path);
735  if (!Factory::GenerateHttpUrl(s3_url, https_url, &obj, err_msg)) {
737  }
738  auto query = obj.find('?');
739  if (query != std::string::npos) {
740  obj.erase(query);
741  }
742  // HEAD of the bucket returns a zero-byte success. List it instead.
743  if (obj.empty()) {
744  auto query_loc = https_url.find('?');
745  https_url += (query_loc == std::string::npos) ? "?" : "&";
746  https_url += "list-type=2&delimiter=/&encoding-type=url";
747  auto expiry = time(NULL) + timeout;
748  return DownloadUrl(
749  https_url,
750  &m_header_callout,
751  new DirListResponseHandler(
752  true, https_url, "", &m_header_callout, new StatHandlerDirectory(handler), expiry, *m_logger
753  ),
754  timeout
755  );
756  }
757  auto [st, fs] = GetFSHandle(cleaned_path);
758  if (!st.IsOK()) {
759  return st;
760  }
761  return fs->Stat(cleaned_path, new StatHandler(cleaned_path, m_url.GetURL(), &m_header_callout, handler, timeout, *m_logger), timeout);
762 }

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

+ Here is the call graph for this function:

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