XRootD
XrdClHttp::Filesystem Class Referencefinal

#include <XrdClHttpFilesystem.hh>

+ Inheritance diagram for XrdClHttp::Filesystem:
+ Collaboration diagram for XrdClHttp::Filesystem:

Public Member Functions

 Filesystem (const std::string &, std::shared_ptr< HandlerQueue > queue, XrdCl::Log *log)
 
virtual ~Filesystem () noexcept
 
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 Prepare (const std::vector< std::string > &fileList, XrdCl::PrepareFlags::Flags flags, uint8_t priority, 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
 
virtual XrdCl::XRootDStatus ThirdPartyCopy (const std::string &source, const std::string &dest, const XrdCl::PropertyList *properties, XrdCl::ProgressHandler *progress_handler, time_t timeout=0) 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 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)
 
- Public Member Functions inherited from XrdCl::ThirdPartyCopyPlugIn
virtual ~ThirdPartyCopyPlugIn ()
 

Detailed Description

Definition at line 52 of file XrdClHttpFilesystem.hh.

Constructor & Destructor Documentation

◆ Filesystem()

XrdClHttp::Filesystem::Filesystem ( const std::string &  ,
std::shared_ptr< HandlerQueue >  queue,
XrdCl::Log *  log 
)

◆ ~Filesystem()

virtual XrdClHttp::Filesystem::~Filesystem ( )
virtualnoexcept

Member Function Documentation

◆ DirList()

XrdCl::XRootDStatus XrdClHttp::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.

◆ GetProperty()

virtual bool XrdClHttp::Filesystem::GetProperty ( const std::string &  name,
std::string &  value 
) const
overridevirtual

◆ Locate()

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

◆ MkDir()

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

◆ Prepare()

XrdCl::XRootDStatus Filesystem::Prepare ( const std::vector< std::string > &  fileList,
XrdCl::PrepareFlags::Flags  flags,
uint8_t  priority,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Prepare

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 247 of file XrdClHttpFilesystem.cc.

253 {
254  (void)priority;
255 
256  if(fileList.empty())
257  {
259  EINVAL, "missing prepare file list");
260  }
261 
263  auto tapeOp = std::make_unique<CurlTapePrepareOp>(
264  handler, m_url.GetURL(), fileList, flags, ts, m_logger,
265  GetConnCallout(),
266  m_header_callout.load(std::memory_order_acquire));
267  return QueueOperation(std::move(tapeOp), "Tape prepare operation");
268 }
static std::string ts()
timestamp output for logging messages
Definition: XrdCephOss.cc:53
static struct timespec GetHeaderTimeoutWithDefault(time_t oper_timeout)
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errInvalidArgs
Definition: XrdClStatus.hh:58

References XrdCl::errInvalidArgs, XrdClHttp::Factory::GetHeaderTimeoutWithDefault(), XrdCl::stError, and ts().

+ Here is the call graph for this function:

◆ Query()

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

◆ Rm()

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

Reimplemented from XrdCl::FileSystemPlugIn.

◆ RmDir()

virtual XrdCl::XRootDStatus XrdClHttp::Filesystem::RmDir ( const std::string &  path,
XrdCl::ResponseHandler *  handler,
time_t  timeout 
)
overridevirtual

◆ SetProperty()

virtual bool XrdClHttp::Filesystem::SetProperty ( const std::string &  name,
const std::string &  value 
)
overridevirtual

◆ Stat()

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

Reimplemented from XrdCl::FileSystemPlugIn.

◆ ThirdPartyCopy()

XrdCl::XRootDStatus Filesystem::ThirdPartyCopy ( const std::string &  source,
const std::string &  dest,
const XrdCl::PropertyList *  properties,
XrdCl::ProgressHandler *  progress_handler,
time_t  timeout = 0 
)
overridevirtual

Third party copy

The copy runs to completion before this method returns.

Parameters
sourcethe file to be copied from
destthe location the file is copied to
propertiesproperties of the copy, none if null
progress_handlerhandler notified while the copy runs, none if null
timeouttimeout value, if 0 the environment default is used
Returns
status of the operation

Implements XrdCl::ThirdPartyCopyPlugIn.

Definition at line 462 of file XrdClHttpFilesystem.cc.

467 {
468  XrdCl::Log *const log = XrdCl::DefaultEnv::GetLog();
469  log->Debug(kLogXrdClHttp, "XrdClHttp::ThirdPartyCopy src %s dst %s", source.c_str(), dest.c_str());
470 
471  if (!is_http_url(source) || !is_http_url(dest))
472  {
473  log->Error(kLogXrdClHttp, "Third party copy can only be done between http(s) protocols");
475  "Third party copy can only be done between http(s) protocols");
476  }
477 
478  TpcMode mode = TpcMode::Pull;
479  int number_of_streams = 1;
480  time_t init_timeout = 0;
481  time_t tpc_timeout = 0;
482  std::string token_file;
483  bool force_overwrite = false;
484 
485  if (properties)
486  {
487  mode = properties->Get<std::string>("thirdPartyMode") != "push" ? TpcMode::Pull : TpcMode::Push;
488  properties->Get("initTimeout", init_timeout);
489  properties->Get("tpcTimeout", tpc_timeout);
490  token_file = properties->Get<std::string>("thirdPartyTokenFile");
491  properties->Get("force", force_overwrite);
492  }
493 
494  // The tpcTimeout property takes precedence over the timeout argument.
495  if (tpc_timeout == 0)
496  tpc_timeout = timeout;
497 
498  if (auto env = XrdCl::DefaultEnv::GetEnv(); env)
499  env->GetInt("SubStreamsPerChannel", number_of_streams);
500 
501  CurlCopyOp::Headers headers;
502  CurlCopyOp::Headers src_hdrs;
503  CurlCopyOp::Headers dst_hdrs;
504 
505  if (!token_file.empty() && !ParseTokenFile(token_file, src_hdrs, dst_hdrs))
507  "Failed to parse the token file '" + token_file + "'");
508 
509  const auto is_unsecure = [] (const CurlCopyOp::Headers &hdrs, const std::string &url)
510  {
511  return XrdCl::URL(url).GetProtocol() != "https"s &&
512  std::any_of(hdrs.begin(), hdrs.end(),
513  [] (const auto &header) { return header.first == "Authorization"s; });
514  };
515 
516  if (is_unsecure(src_hdrs, source) || is_unsecure(dst_hdrs, dest))
517  {
518  log->Error(kLogXrdClHttp, "Refusing to send an Authorization header over an unencrypted http URL");
520  "Refusing to send an Authorization header over an unencrypted http URL");
521  }
522 
523  // In push mode the source writes the destination with a PUT, which may
524  // replace an existing file whatever the Overwrite header says. Thus check
525  // the destination first, as the destination server may not honor it.
526  if (mode == TpcMode::Push && !force_overwrite &&
527  stat_size(*m_queue, dest, dst_hdrs, init_timeout, log, "destination"))
528  {
529  log->Error(kLogXrdClHttp, "The destination %s exists", dest.c_str());
531  "The destination exists; use --force to replace it");
532  }
533 
534  headers.emplace_back("X-Number-Of-Streams"s, std::to_string(number_of_streams));
535 
536  // The destination headers reach the destination in both modes: directly
537  // in pull mode, with the TransferHeader prefix in push mode.
538  dst_hdrs.emplace_back("Overwrite"s, force_overwrite ? "T"s : "F"s);
539 
540  std::size_t size = 0;
541 
542  if (progress_handler)
543  {
544  size = stat_size(*m_queue, source, src_hdrs, init_timeout, log, "source").value_or(0);
545  progress_handler->HandleProgress(0, size);
546  }
547 
548  const auto rh = std::make_shared<SyncResponseHandler>();
549  const auto op = std::make_shared<CopyOp>(rh.get(), source, src_hdrs, dest, dst_hdrs, headers,
550  mode, timespec{tpc_timeout, 0}, log, nullptr);
551  op->SetProgressHandler(progress_handler);
552 
553  try
554  {
555  m_queue->Produce(std::shared_ptr<CopyOp>(op.get(), [rh, op](auto){}));
556  }
557  catch (const std::exception &e) {
558  log->Warning(kLogXrdClHttp, "Failed to add copy op to queue - %s", e.what());
560  }
561 
562  if (!rh->wait(std::chrono::seconds(tpc_timeout)))
563  return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOperationExpired, 0, "Operation expired: Operation timed out"s);
564 
565  if (op->IsDone() && !op->IsSentSuccessfully())
566  return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errPipelineFailed, 0, op->GetSendingFailureMessage());
567 
568  if (progress_handler && size > 0)
569  progress_handler->HandleProgress(size, size);
570 
571  return XrdCl::XRootDStatus();
572 }
@ kXR_ItExists
Definition: XProtocol.hh:1050
static bool is_http_url(const std::string &url)
std::vector< std::pair< std::string, std::string > > Headers
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
Handle diagnostics.
Definition: XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
void Warning(uint64_t topic, const char *format,...)
Report a warning.
Definition: XrdClLog.cc:248
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
virtual void HandleProgress(std::size_t processed, std::size_t total=0)=0
bool Get(const std::string &name, Item &item) const
URL representation.
Definition: XrdClURL.hh:31
const std::string & GetProtocol() const
Get the protocol.
Definition: XrdClURL.hh:118
static std::optional< std::size_t > stat_size(HandlerQueue &queue, const std::string &url, const CurlCopyOp::Headers &hdrs, time_t timeout, XrdCl::Log *log, const char *what)
bool ParseTokenFile(const std::string &token_file, CurlCopyOp::Headers &src_hdrs, CurlCopyOp::Headers &dst_hdrs)
const uint16_t errErrorResponse
Definition: XrdClStatus.hh:105
const uint16_t errOperationExpired
Definition: XrdClStatus.hh:90
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:56
const uint16_t errPipelineFailed
Pipeline failed and operation couldn't be executed.
Definition: XrdClStatus.hh:66
const uint16_t errAuthFailed
Definition: XrdClStatus.hh:88
const uint64_t kLogXrdClHttp

References XrdCl::Log::Debug(), XrdCl::errAuthFailed, XrdCl::errErrorResponse, XrdCl::errInternal, XrdCl::errInvalidArgs, XrdCl::errOperationExpired, XrdCl::Log::Error(), XrdCl::errPipelineFailed, XrdCl::PropertyList::Get(), XrdCl::DefaultEnv::GetEnv(), XrdCl::DefaultEnv::GetLog(), XrdCl::URL::GetProtocol(), XrdCl::ProgressHandler::HandleProgress(), is_http_url(), XrdClHttp::kLogXrdClHttp, kXR_ItExists, XrdClHttp::ParseTokenFile(), XrdClHttp::stat_size(), XrdCl::stError, and XrdCl::Log::Warning().

+ Here is the call graph for this function:

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