XRootD
XrdCl::FileStateHandler Class Reference

Handle the stateful operations. More...

#include <XrdClFileStateHandler.hh>

+ Collaboration diagram for XrdCl::FileStateHandler:

Public Types

enum  FileStatus {
  Closed ,
  Opened ,
  Error ,
  Recovering ,
  OpenInProgress ,
  CloseInProgress
}
 State of the file. More...
 

Public Member Functions

 FileStateHandler (bool useVirtRedirector, FilePlugIn *&plugin)
 
 FileStateHandler (FilePlugIn *&plugin)
 Constructor. More...
 
 ~FileStateHandler ()
 Destructor. More...
 
void AfterForkChild ()
 Called in the child process after the fork. More...
 
bool GetProperty (const std::string &name, std::string &value) const
 
bool IsOpen () const
 Check if the file is open. More...
 
bool IsSecure () const
 Check if the file is using an encrypted connection. More...
 
void Lock ()
 Lock the internal lock. More...
 
void OnClose (const XRootDStatus *status)
 Process the results of the closing operation. More...
 
void OnOpen (const XRootDStatus *status, const OpenInfo *openInfo, const HostList *hostList)
 Process the results of the opening operation. More...
 
bool SetProperty (const std::string &name, const std::string &value)
 
void Tick (time_t now)
 Tick. More...
 
void TimeOutRequests (time_t now)
 Declare timeout on requests being recovered. More...
 
void UnLock ()
 Unlock the internal lock. More...
 

Static Public Member Functions

static XRootDStatus Checkpoint (std::shared_ptr< FileStateHandler > &self, kXR_char code, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus ChkptWrt (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus ChkptWrtV (std::shared_ptr< FileStateHandler > &self, uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Close (std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus DelXAttr (std::shared_ptr< FileStateHandler > &self, const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Fcntl (std::shared_ptr< FileStateHandler > &self, const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus GetXAttr (std::shared_ptr< FileStateHandler > &self, const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus ListXAttr (std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
 
static void OnStateError (std::shared_ptr< FileStateHandler > &self, XRootDStatus *status, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
 Handle an error while sending a stateful message. More...
 
static void OnStateRedirection (std::shared_ptr< FileStateHandler > &self, const std::string &redirectUrl, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
 Handle stateful redirect. More...
 
static void OnStateResponse (std::shared_ptr< FileStateHandler > &self, XRootDStatus *status, Message *message, AnyObject *response, HostList *hostList)
 Handle stateful response. More...
 
static XRootDStatus Open (std::shared_ptr< FileStateHandler > &self, const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus PgRead (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus PgReadImpl (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, uint16_t flags, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus PgReadRetry (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, size_t pgnb, void *buffer, PgReadHandler *handler, uint16_t timeout=0)
 
static XRootDStatus PgWrite (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus PgWriteImpl (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, kXR_char flags, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus PgWriteRetry (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, uint32_t digest, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Read (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus ReadV (std::shared_ptr< FileStateHandler > &self, uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus SetXAttr (std::shared_ptr< FileStateHandler > &self, const std::vector< xattr_t > &attrs, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Stat (std::shared_ptr< FileStateHandler > &self, bool force, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Sync (std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Truncate (std::shared_ptr< FileStateHandler > &self, uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus TryOtherServer (std::shared_ptr< FileStateHandler > &self, uint16_t timeout)
 Try other data server. More...
 
static XRootDStatus VectorRead (std::shared_ptr< FileStateHandler > &self, const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus VectorWrite (std::shared_ptr< FileStateHandler > &self, const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Visa (std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Write (std::shared_ptr< FileStateHandler > &self, uint64_t offset, Buffer &&buffer, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Write (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus Write (std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, Optional< uint64_t > fdoff, int fd, ResponseHandler *handler, uint16_t timeout=0)
 
static XRootDStatus WriteV (std::shared_ptr< FileStateHandler > &self, uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
 

Friends

class ::OpenHandler
 
class ::PgReadHandler
 
class ::PgReadRetryHandler
 
class ::PgReadSubstitutionHandler
 

Detailed Description

Handle the stateful operations.

Definition at line 79 of file XrdClFileStateHandler.hh.

Member Enumeration Documentation

◆ FileStatus

State of the file.

Enumerator
Closed 

The file is closed.

Opened 

Opening has succeeded.

Error 

Opening has failed.

Recovering 

Recovering from an error.

OpenInProgress 

Opening is in progress.

CloseInProgress 

Closing operation is in progress.

Definition at line 90 of file XrdClFileStateHandler.hh.

91  {
92  Closed,
93  Opened,
94  Error,
95  Recovering,
98  };
@ OpenInProgress
Opening is in progress.
@ CloseInProgress
Closing operation is in progress.
@ Closed
The file is closed.
@ Opened
Opening has succeeded.
@ Error
Opening has failed.
@ Recovering
Recovering from an error.

Constructor & Destructor Documentation

◆ FileStateHandler() [1/2]

XrdCl::FileStateHandler::FileStateHandler ( FilePlugIn *&  plugin)

Constructor.

Definition at line 640 of file XrdClFileStateHandler.cc.

640  :
641  pFileState( Closed ),
642  pStatInfo( 0 ),
643  pFileUrl( 0 ),
644  pDataServer( 0 ),
645  pLoadBalancer( 0 ),
646  pStateRedirect( 0 ),
647  pWrtRecoveryRedir( 0 ),
648  pFileHandle( 0 ),
649  pOpenMode( 0 ),
650  pOpenFlags( 0 ),
651  pSessionId( 0 ),
652  pDoRecoverRead( true ),
653  pDoRecoverWrite( true ),
654  pFollowRedirects( true ),
655  pUseVirtRedirector( true ),
656  pIsChannelEncrypted( false ),
657  pAllowBundledClose( false ),
658  pPlugin( plugin )
659  {
660  pFileHandle = new uint8_t[4];
661  ResetMonitoringVars();
664  pLFileHandler = new LocalFileHandler();
665  }
static FileTimer * GetFileTimer()
Get file timer task.
static ForkHandler * GetForkHandler()
Get the fork handler.
void RegisterFileObject(FileStateHandler *file)
Register a file state handler.
void RegisterFileObject(FileStateHandler *file)
Register a file object.

References XrdCl::DefaultEnv::GetFileTimer(), XrdCl::DefaultEnv::GetForkHandler(), XrdCl::FileTimer::RegisterFileObject(), and XrdCl::ForkHandler::RegisterFileObject().

+ Here is the call graph for this function:

◆ FileStateHandler() [2/2]

XrdCl::FileStateHandler::FileStateHandler ( bool  useVirtRedirector,
FilePlugIn *&  plugin 
)

Constructor

Parameters
useVirtRedirectorif true Metalink files will be treated as a VirtualRedirectors

Definition at line 673 of file XrdClFileStateHandler.cc.

673  :
674  pFileState( Closed ),
675  pStatInfo( 0 ),
676  pFileUrl( 0 ),
677  pDataServer( 0 ),
678  pLoadBalancer( 0 ),
679  pStateRedirect( 0 ),
680  pWrtRecoveryRedir( 0 ),
681  pFileHandle( 0 ),
682  pOpenMode( 0 ),
683  pOpenFlags( 0 ),
684  pSessionId( 0 ),
685  pDoRecoverRead( true ),
686  pDoRecoverWrite( true ),
687  pFollowRedirects( true ),
688  pUseVirtRedirector( useVirtRedirector ),
689  pAllowBundledClose( false ),
690  pPlugin( plugin )
691  {
692  pFileHandle = new uint8_t[4];
693  ResetMonitoringVars();
696  pLFileHandler = new LocalFileHandler();
697  }

References XrdCl::DefaultEnv::GetFileTimer(), XrdCl::DefaultEnv::GetForkHandler(), XrdCl::FileTimer::RegisterFileObject(), and XrdCl::ForkHandler::RegisterFileObject().

+ Here is the call graph for this function:

◆ ~FileStateHandler()

XrdCl::FileStateHandler::~FileStateHandler ( )

Destructor.

Definition at line 702 of file XrdClFileStateHandler.cc.

703  {
704  //--------------------------------------------------------------------------
705  // This, in principle, should never ever happen. Except for the case
706  // when we're interfaced with ROOT that may call this desctructor from
707  // its garbage collector, from its __cxa_finalize, ie. after the XrdCl lib
708  // has been finalized by the linker. So, if we don't have the log object
709  // at this point we just give up the hope.
710  //--------------------------------------------------------------------------
711  if( DefaultEnv::GetLog() && pSessionId && !pDataServer->IsLocalFile() ) // if the file object was bound to a physical connection
712  DefaultEnv::GetPostMaster()->DecFileInstCnt( *pDataServer );
713 
716 
719 
720  if( pFileState != Closed && DefaultEnv::GetLog() )
721  {
722  XRootDStatus st;
723  MonitorClose( &st );
724  ResetMonitoringVars();
725  }
726 
727  // check if the logger is still there, this is only for root, as root might
728  // have unload us already so in this case we don't want to do anything
729  if( DefaultEnv::GetLog() && pUseVirtRedirector && pFileUrl && pFileUrl->IsMetalink() )
730  {
732  registry.Release( *pFileUrl );
733  }
734 
735  delete pStatInfo;
736  delete pFileUrl;
737  delete pDataServer;
738  delete pLoadBalancer;
739  delete [] pFileHandle;
740  delete pLFileHandler;
741  }
static Log * GetLog()
Get default log.
static PostMaster * GetPostMaster()
Get default post master.
void UnRegisterFileObject(FileStateHandler *file)
Un-register a file state handler.
void UnRegisterFileObject(FileStateHandler *file)
void DecFileInstCnt(const URL &url)
Decrement file object instance count bound to this channel.
Singleton access to URL to virtual redirector mapping.
static RedirectorRegistry & Instance()
Returns reference to the single instance.
void Release(const URL &url)
Release the virtual redirector associated with the given URL.
bool IsMetalink() const
Is it a URL to a metalink.
Definition: XrdClURL.cc:451
bool IsLocalFile() const
Definition: XrdClURL.cc:460

References Closed, XrdCl::PostMaster::DecFileInstCnt(), XrdCl::DefaultEnv::GetFileTimer(), XrdCl::DefaultEnv::GetForkHandler(), XrdCl::DefaultEnv::GetLog(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::RedirectorRegistry::Instance(), XrdCl::URL::IsLocalFile(), XrdCl::URL::IsMetalink(), XrdCl::RedirectorRegistry::Release(), XrdCl::FileTimer::UnRegisterFileObject(), and XrdCl::ForkHandler::UnRegisterFileObject().

+ Here is the call graph for this function:

Member Function Documentation

◆ AfterForkChild()

void XrdCl::FileStateHandler::AfterForkChild ( )

Called in the child process after the fork.

Definition at line 2744 of file XrdClFileStateHandler.cc.

2745  {
2746  Log *log = DefaultEnv::GetLog();
2747 
2748  if( pFileState == Closed || pFileState == Error )
2749  return;
2750 
2751  if( (IsReadOnly() && pDoRecoverRead) ||
2752  (!IsReadOnly() && pDoRecoverWrite) )
2753  {
2754  log->Debug( FileMsg, "[0x%x@%s] Putting the file in recovery state in "
2755  "process %d", this, pFileUrl->GetURL().c_str(), getpid() );
2756  pFileState = Recovering;
2757  pInTheFly.clear();
2758  pToBeRecovered.clear();
2759  }
2760  else
2761  pFileState = Error;
2762  }
Handle diagnostics.
Definition: XrdClLog.hh:101
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
const uint64_t FileMsg

References Closed, XrdCl::Log::Debug(), Error, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), XrdCl::URL::GetURL(), and Recovering.

+ Here is the call graph for this function:

◆ Checkpoint()

XRootDStatus XrdCl::FileStateHandler::Checkpoint ( std::shared_ptr< FileStateHandler > &  self,
kXR_char  code,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Create a checkpoint

Parameters
handler: handler to be notified when the response arrives, the response parameter will hold a std::vector of XAttr objects
timeout: timeout value, if 0 the environment default will be used
Returns
: status of the operation

Definition at line 2058 of file XrdClFileStateHandler.cc.

2062  {
2063  XrdSysMutexHelper scopedLock( self->pMutex );
2064 
2065  if( self->pFileState == Error ) return self->pStatus;
2066 
2067  if( self->pFileState != Opened && self->pFileState != Recovering )
2068  return XRootDStatus( stError, errInvalidOp );
2069 
2070  Log *log = DefaultEnv::GetLog();
2071  log->Debug( FileMsg, "[0x%x@%s] Sending a checkpoint command for "
2072  "handle 0x%x to %s", self.get(), self->pFileUrl->GetURL().c_str(),
2073  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
2074 
2075  Message *msg;
2076  ClientChkPointRequest *req;
2077  MessageUtils::CreateRequest( msg, req );
2078 
2079  req->requestid = kXR_chkpoint;
2080  req->opcode = code;
2081  memcpy( req->fhandle, self->pFileHandle, 4 );
2082 
2083  MessageSendParams params;
2084  params.timeout = timeout;
2085  params.followRedirects = false;
2086  params.stateful = true;
2087 
2089 
2091  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
2092 
2093  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
2094  }
@ kXR_chkpoint
Definition: XProtocol.hh:124
kXR_char fhandle[4]
Definition: XProtocol.hh:204
static void ProcessSendParams(MessageSendParams &sendParams)
Process sending params.
static void CreateRequest(Message *&msg, Request *&req, uint32_t payloadSize=0)
Create a message.
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
static void SetDescription(Message *msg)
Get the description of a message.
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errInvalidOp
Definition: XrdClStatus.hh:51

References XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientChkPointRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_chkpoint, ClientChkPointRequest::opcode, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientChkPointRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

+ Here is the call graph for this function:

◆ ChkptWrt()

XRootDStatus XrdCl::FileStateHandler::ChkptWrt ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
const void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Checkpointed write - async

Parameters
offsetoffset from the beginning of the file
sizenumber of bytes to be written
buffera pointer to the buffer holding the data to be written
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 2107 of file XrdClFileStateHandler.cc.

2113  {
2114  XrdSysMutexHelper scopedLock( self->pMutex );
2115 
2116  if( self->pFileState == Error ) return self->pStatus;
2117 
2118  if( self->pFileState != Opened && self->pFileState != Recovering )
2119  return XRootDStatus( stError, errInvalidOp );
2120 
2121  Log *log = DefaultEnv::GetLog();
2122  log->Debug( FileMsg, "[0x%x@%s] Sending a write command for handle 0x%x to "
2123  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
2124  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
2125 
2126  Message *msg;
2127  ClientChkPointRequest *req;
2128  MessageUtils::CreateRequest( msg, req, sizeof( ClientWriteRequest ) );
2129 
2130  req->requestid = kXR_chkpoint;
2131  req->opcode = kXR_ckpXeq;
2132  req->dlen = 24; // as specified in the protocol specification
2133  memcpy( req->fhandle, self->pFileHandle, 4 );
2134 
2136  wrtreq->requestid = kXR_write;
2137  wrtreq->offset = offset;
2138  wrtreq->dlen = size;
2139  memcpy( wrtreq->fhandle, self->pFileHandle, 4 );
2140 
2141  ChunkList *list = new ChunkList();
2142  list->push_back( ChunkInfo( 0, size, (char*)buffer ) );
2143 
2144  MessageSendParams params;
2145  params.timeout = timeout;
2146  params.followRedirects = false;
2147  params.stateful = true;
2148  params.chunkList = list;
2149 
2151 
2153  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
2154 
2155  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
2156  }
kXR_unt16 requestid
Definition: XProtocol.hh:804
kXR_char fhandle[4]
Definition: XProtocol.hh:805
static const int kXR_ckpXeq
Definition: XProtocol.hh:216
@ kXR_write
Definition: XProtocol.hh:131
kXR_int64 offset
Definition: XProtocol.hh:806
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
std::vector< ChunkInfo > ChunkList
List of chunks.
Describe a data chunk for vector read.

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientChkPointRequest::dlen, ClientWriteRequest::dlen, XrdCl::errInvalidOp, Error, ClientChkPointRequest::fhandle, ClientWriteRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetLog(), kXR_chkpoint, kXR_ckpXeq, kXR_write, ClientWriteRequest::offset, ClientChkPointRequest::opcode, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientChkPointRequest::requestid, ClientWriteRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

+ Here is the call graph for this function:

◆ ChkptWrtV()

XRootDStatus XrdCl::FileStateHandler::ChkptWrtV ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
const struct iovec *  iov,
int  iovcnt,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Checkpointed WriteV - async

Parameters
offsetoffset from the beginning of the file
iovlist of the buffers to be written
iovcntnumber of buffers
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 then the environment default will be used
Returns
status of the operation

Write scattered buffers in one operation - async

Parameters
offsetoffset from the beginning of the file
iovlist of the buffers to be written
iovcntnumber of buffers
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 then the environment default will be used
Returns
status of the operation

Definition at line 2169 of file XrdClFileStateHandler.cc.

2175  {
2176  XrdSysMutexHelper scopedLock( self->pMutex );
2177 
2178  if( self->pFileState == Error ) return self->pStatus;
2179 
2180  if( self->pFileState != Opened && self->pFileState != Recovering )
2181  return XRootDStatus( stError, errInvalidOp );
2182 
2183  Log *log = DefaultEnv::GetLog();
2184  log->Debug( FileMsg, "[0x%x@%s] Sending a write command for handle 0x%x to "
2185  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
2186  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
2187 
2188  Message *msg;
2189  ClientChkPointRequest *req;
2190  MessageUtils::CreateRequest( msg, req, sizeof( ClientWriteRequest ) );
2191 
2192  req->requestid = kXR_chkpoint;
2193  req->opcode = kXR_ckpXeq;
2194  req->dlen = 24; // as specified in the protocol specification
2195  memcpy( req->fhandle, self->pFileHandle, 4 );
2196 
2197  ChunkList *list = new ChunkList();
2198  uint32_t size = 0;
2199  for( int i = 0; i < iovcnt; ++i )
2200  {
2201  if( iov[i].iov_len == 0 ) continue;
2202  size += iov[i].iov_len;
2203  list->push_back( ChunkInfo( 0, iov[i].iov_len,
2204  (char*)iov[i].iov_base ) );
2205  }
2206 
2208  wrtreq->requestid = kXR_write;
2209  wrtreq->offset = offset;
2210  wrtreq->dlen = size;
2211  memcpy( wrtreq->fhandle, self->pFileHandle, 4 );
2212 
2213  MessageSendParams params;
2214  params.timeout = timeout;
2215  params.followRedirects = false;
2216  params.stateful = true;
2217  params.chunkList = list;
2218 
2220 
2222  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
2223 
2224  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
2225  }

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientChkPointRequest::dlen, ClientWriteRequest::dlen, XrdCl::errInvalidOp, Error, ClientChkPointRequest::fhandle, ClientWriteRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetLog(), kXR_chkpoint, kXR_ckpXeq, kXR_write, ClientWriteRequest::offset, ClientChkPointRequest::opcode, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientChkPointRequest::requestid, ClientWriteRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

+ Here is the call graph for this function:

◆ Close()

XRootDStatus XrdCl::FileStateHandler::Close ( std::shared_ptr< FileStateHandler > &  self,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Close the file object

Parameters
handlerhandler to be notified about the status of the operation
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 873 of file XrdClFileStateHandler.cc.

876  {
877  XrdSysMutexHelper scopedLock( self->pMutex );
878 
879  //--------------------------------------------------------------------------
880  // Check if we can proceed
881  //--------------------------------------------------------------------------
882  if( self->pFileState == Error )
883  return self->pStatus;
884 
885  if( self->pFileState == CloseInProgress )
887 
888  if( self->pFileState == Closed )
889  return XRootDStatus( stOK, suAlreadyDone );
890 
891  if( self->pFileState == OpenInProgress || self->pFileState == Recovering )
892  return XRootDStatus( stError, errInvalidOp );
893 
894  if( !self->pAllowBundledClose && !self->pInTheFly.empty() )
895  return XRootDStatus( stError, errInvalidOp );
896 
897  self->pFileState = CloseInProgress;
898 
899  Log *log = DefaultEnv::GetLog();
900  log->Debug( FileMsg, "[0x%x@%s] Sending a close command for handle 0x%x to "
901  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
902  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
903 
904  //--------------------------------------------------------------------------
905  // Close the file
906  //--------------------------------------------------------------------------
907  Message *msg;
908  ClientCloseRequest *req;
909  MessageUtils::CreateRequest( msg, req );
910 
911  req->requestid = kXR_close;
912  memcpy( req->fhandle, self->pFileHandle, 4 );
913 
915  msg->SetSessionId( self->pSessionId );
916  CloseHandler *closeHandler = new CloseHandler( self, handler, msg );
917  MessageSendParams params;
918  params.timeout = timeout;
919  params.followRedirects = false;
920  params.stateful = true;
922 
923  XRootDStatus st = self->IssueRequest( *self->pDataServer, msg, closeHandler, params );
924 
925  if( !st.IsOK() )
926  {
927  // an invalid-session error means the connection to the server has been
928  // closed, which in turn means that the server closed the file already
929  if( st.code == errInvalidSession || st.code == errSocketDisconnected ||
931  st.code == errPollerError || st.code == errSocketError )
932  {
933  self->pFileState = Closed;
934  ResponseJob *job = new ResponseJob( closeHandler, new XRootDStatus(),
935  nullptr, nullptr );
937  return XRootDStatus();
938  }
939 
940  delete closeHandler;
941  self->pStatus = st;
942  self->pFileState = Error;
943  return st;
944  }
945  return st;
946  }
kXR_unt16 requestid
Definition: XProtocol.hh:228
kXR_char fhandle[4]
Definition: XProtocol.hh:229
@ kXR_close
Definition: XProtocol.hh:115
void QueueJob(Job *job, void *arg=0)
Add a job to be run.
void SetSessionId(uint64_t sessionId)
Set the session ID which this message is meant for.
JobManager * GetJobManager()
Get the job manager object user by the post master.
Call the user callback.
const uint16_t errSocketOptError
Definition: XrdClStatus.hh:76
const uint16_t errPollerError
Definition: XrdClStatus.hh:75
const uint16_t errInProgress
Definition: XrdClStatus.hh:59
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31
const uint16_t suAlreadyDone
Definition: XrdClStatus.hh:42
const uint16_t errConnectionError
Definition: XrdClStatus.hh:78
const uint16_t errSocketError
Definition: XrdClStatus.hh:72
const uint16_t errInvalidSession
Definition: XrdClStatus.hh:79
const uint16_t errSocketDisconnected
Definition: XrdClStatus.hh:74
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:147
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124

References Closed, CloseInProgress, XrdCl::Status::code, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errConnectionError, XrdCl::errInProgress, XrdCl::errInvalidOp, XrdCl::errInvalidSession, Error, XrdCl::errPollerError, XrdCl::errSocketDisconnected, XrdCl::errSocketError, XrdCl::errSocketOptError, ClientCloseRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::PostMaster::GetJobManager(), XrdCl::DefaultEnv::GetLog(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::Status::IsOK(), kXR_close, OpenInProgress, XrdCl::MessageUtils::ProcessSendParams(), XrdCl::JobManager::QueueJob(), Recovering, ClientCloseRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::Message::SetSessionId(), XrdCl::MessageSendParams::stateful, XrdCl::stError, XrdCl::stOK, XrdCl::suAlreadyDone, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Close().

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

◆ DelXAttr()

XRootDStatus XrdCl::FileStateHandler::DelXAttr ( std::shared_ptr< FileStateHandler > &  self,
const std::vector< std::string > &  attrs,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Delete extended attributes - async

Parameters
attrs: list of extended attributes to set
handler: handler to be notified when the response arrives, the response parameter will hold a std::vector of XAttrStatus objects
timeout: timeout value, if 0 the environment default will be used
Returns
: status of the operation

Definition at line 1997 of file XrdClFileStateHandler.cc.

2001  {
2002  XrdSysMutexHelper scopedLock( self->pMutex );
2003 
2004  if( self->pFileState == Error ) return self->pStatus;
2005 
2006  if( self->pFileState != Opened && self->pFileState != Recovering )
2007  return XRootDStatus( stError, errInvalidOp );
2008 
2009  Log *log = DefaultEnv::GetLog();
2010  log->Debug( FileMsg, "[0x%x@%s] Sending a fattr del command for handle 0x%x to "
2011  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
2012  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
2013 
2014  //--------------------------------------------------------------------------
2015  // Issue a new fattr del request
2016  //--------------------------------------------------------------------------
2017  return XAttrOperationImpl( self, kXR_fattrDel, 0, attrs, handler, timeout );
2018  }
@ kXR_fattrDel
Definition: XProtocol.hh:270

References XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), kXR_fattrDel, Opened, Recovering, and XrdCl::stError.

Referenced by XrdCl::File::DelXAttr().

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

◆ Fcntl()

XRootDStatus XrdCl::FileStateHandler::Fcntl ( std::shared_ptr< FileStateHandler > &  self,
const Buffer arg,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Performs a custom operation on an open file, server implementation dependent - async

Parameters
argquery argument
handlerhandler to be notified when the response arrives, the response parameter will hold a Buffer object if the procedure is successful
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1864 of file XrdClFileStateHandler.cc.

1868  {
1869  XrdSysMutexHelper scopedLock( self->pMutex );
1870 
1871  if( self->pFileState == Error ) return self->pStatus;
1872 
1873  if( self->pFileState != Opened && self->pFileState != Recovering )
1874  return XRootDStatus( stError, errInvalidOp );
1875 
1876  Log *log = DefaultEnv::GetLog();
1877  log->Debug( FileMsg, "[0x%x@%s] Sending a fcntl command for handle 0x%x to "
1878  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1879  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1880 
1881  Message *msg;
1882  ClientQueryRequest *req;
1883  MessageUtils::CreateRequest( msg, req, arg.GetSize() );
1884 
1885  req->requestid = kXR_query;
1886  req->infotype = kXR_Qopaqug;
1887  req->dlen = arg.GetSize();
1888  memcpy( req->fhandle, self->pFileHandle, 4 );
1889  msg->Append( arg.GetBuffer(), arg.GetSize(), 24 );
1890 
1891  MessageSendParams params;
1892  params.timeout = timeout;
1893  params.followRedirects = false;
1894  params.stateful = true;
1896 
1898  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1899 
1900  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1901  }
kXR_unt16 requestid
Definition: XProtocol.hh:630
kXR_unt16 infotype
Definition: XProtocol.hh:631
kXR_char fhandle[4]
Definition: XProtocol.hh:633
@ kXR_query
Definition: XProtocol.hh:113
@ kXR_Qopaqug
Definition: XProtocol.hh:625
void Append(const char *buffer, uint32_t size)
Append data at the position pointed to by the append cursor.
Definition: XrdClBuffer.hh:164
uint32_t GetSize() const
Get the size of the message.
Definition: XrdClBuffer.hh:132

References XrdCl::Buffer::Append(), XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientQueryRequest::dlen, XrdCl::errInvalidOp, Error, ClientQueryRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetLog(), XrdCl::Buffer::GetSize(), ClientQueryRequest::infotype, kXR_Qopaqug, kXR_query, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientQueryRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Fcntl().

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

◆ GetProperty()

bool XrdCl::FileStateHandler::GetProperty ( const std::string &  name,
std::string &  value 
) const

Get file property

See also
File::SetProperty for property list

Definition at line 2276 of file XrdClFileStateHandler.cc.

2278  {
2279  XrdSysMutexHelper scopedLock( pMutex );
2280  if( name == "ReadRecovery" )
2281  {
2282  if( pDoRecoverRead ) value = "true";
2283  else value = "false";
2284  return true;
2285  }
2286  else if( name == "WriteRecovery" )
2287  {
2288  if( pDoRecoverWrite ) value = "true";
2289  else value = "false";
2290  return true;
2291  }
2292  else if( name == "FollowRedirects" )
2293  {
2294  if( pFollowRedirects ) value = "true";
2295  else value = "false";
2296  return true;
2297  }
2298  else if( name == "DataServer" && pDataServer )
2299  { value = pDataServer->GetHostId(); return true; }
2300  else if( name == "LastURL" && pDataServer )
2301  { value = pDataServer->GetURL(); return true; }
2302  else if( name == "WrtRecoveryRedir" && pWrtRecoveryRedir )
2303  { value = pWrtRecoveryRedir->GetHostId(); return true; }
2304  value = "";
2305  return false;
2306  }
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:94

References XrdCl::URL::GetHostId(), and XrdCl::URL::GetURL().

+ Here is the call graph for this function:

◆ GetXAttr()

XRootDStatus XrdCl::FileStateHandler::GetXAttr ( std::shared_ptr< FileStateHandler > &  self,
const std::vector< std::string > &  attrs,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Get extended attributes - async

Parameters
attrs: list of extended attributes to get
handler: handler to be notified when the response arrives, the response parameter will hold a std::vector of XAttr objects
timeout: timeout value, if 0 the environment default will be used
Returns
: status of the operation

Definition at line 1971 of file XrdClFileStateHandler.cc.

1975  {
1976  XrdSysMutexHelper scopedLock( self->pMutex );
1977 
1978  if( self->pFileState == Error ) return self->pStatus;
1979 
1980  if( self->pFileState != Opened && self->pFileState != Recovering )
1981  return XRootDStatus( stError, errInvalidOp );
1982 
1983  Log *log = DefaultEnv::GetLog();
1984  log->Debug( FileMsg, "[0x%x@%s] Sending a fattr get command for handle 0x%x to "
1985  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1986  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1987 
1988  //--------------------------------------------------------------------------
1989  // Issue a new fattr get request
1990  //--------------------------------------------------------------------------
1991  return XAttrOperationImpl( self, kXR_fattrGet, 0, attrs, handler, timeout );
1992  }
@ kXR_fattrGet
Definition: XProtocol.hh:271

References XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), kXR_fattrGet, Opened, Recovering, and XrdCl::stError.

Referenced by XrdCl::File::GetXAttr().

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

◆ IsOpen()

bool XrdCl::FileStateHandler::IsOpen ( ) const

Check if the file is open.

Definition at line 2230 of file XrdClFileStateHandler.cc.

2231  {
2232  XrdSysMutexHelper scopedLock( pMutex );
2233 
2234  if( pFileState == Opened || pFileState == Recovering )
2235  return true;
2236  return false;
2237  }

References Opened, and Recovering.

◆ IsSecure()

bool XrdCl::FileStateHandler::IsSecure ( ) const
inline

Check if the file is using an encrypted connection.

Definition at line 658 of file XrdClFileStateHandler.hh.

659  {
660  return pIsChannelEncrypted;
661  }

◆ ListXAttr()

XRootDStatus XrdCl::FileStateHandler::ListXAttr ( std::shared_ptr< FileStateHandler > &  self,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

List extended attributes - async

Parameters
handler: handler to be notified when the response arrives, the response parameter will hold a std::vector of XAttr objects
timeout: timeout value, if 0 the environment default will be used
Returns
: status of the operation

Definition at line 2023 of file XrdClFileStateHandler.cc.

2026  {
2027  XrdSysMutexHelper scopedLock( self->pMutex );
2028 
2029  if( self->pFileState == Error ) return self->pStatus;
2030 
2031  if( self->pFileState != Opened && self->pFileState != Recovering )
2032  return XRootDStatus( stError, errInvalidOp );
2033 
2034  Log *log = DefaultEnv::GetLog();
2035  log->Debug( FileMsg, "[0x%x@%s] Sending a fattr list command for handle 0x%x to "
2036  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
2037  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
2038 
2039  //--------------------------------------------------------------------------
2040  // Issue a new fattr get request
2041  //--------------------------------------------------------------------------
2042  static const std::vector<std::string> nothing;
2043  return XAttrOperationImpl( self, kXR_fattrList, ClientFattrRequest::aData,
2044  nothing, handler, timeout );
2045  }
@ kXR_fattrList
Definition: XProtocol.hh:272
static const int aData
Definition: XProtocol.hh:298

References ClientFattrRequest::aData, XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), kXR_fattrList, Opened, Recovering, and XrdCl::stError.

Referenced by XrdCl::File::ListXAttr().

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

◆ Lock()

void XrdCl::FileStateHandler::Lock ( )
inline

Lock the internal lock.

Definition at line 680 of file XrdClFileStateHandler.hh.

681  {
682  pMutex.Lock();
683  }

◆ OnClose()

void XrdCl::FileStateHandler::OnClose ( const XRootDStatus status)

Process the results of the closing operation.

Definition at line 2452 of file XrdClFileStateHandler.cc.

2453  {
2454  Log *log = DefaultEnv::GetLog();
2455  XrdSysMutexHelper scopedLock( pMutex );
2456 
2457  log->Debug( FileMsg, "[0x%x@%s] Close returned from %s with: %s", this,
2458  pFileUrl->GetURL().c_str(), pDataServer->GetHostId().c_str(),
2459  status->ToStr().c_str() );
2460 
2461  log->Dump( FileMsg, "[0x%x@%s] Items in the fly %d, queued for recovery %d",
2462  this, pFileUrl->GetURL().c_str(), pInTheFly.size(),
2463  pToBeRecovered.size() );
2464 
2465  MonitorClose( status );
2466  ResetMonitoringVars();
2467 
2468  pStatus = *status;
2469  pFileState = Closed;
2470  }
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
Definition: XrdClLog.cc:299
std::string ToStr() const
Convert to string.

References Closed, XrdCl::Log::Debug(), XrdCl::Log::Dump(), XrdCl::FileMsg, XrdCl::URL::GetHostId(), XrdCl::DefaultEnv::GetLog(), XrdCl::URL::GetURL(), and XrdCl::XRootDStatus::ToStr().

+ Here is the call graph for this function:

◆ OnOpen()

void XrdCl::FileStateHandler::OnOpen ( const XRootDStatus status,
const OpenInfo openInfo,
const HostList hostList 
)

Process the results of the opening operation.

Definition at line 2311 of file XrdClFileStateHandler.cc.

2314  {
2315  Log *log = DefaultEnv::GetLog();
2316  XrdSysMutexHelper scopedLock( pMutex );
2317 
2318  //--------------------------------------------------------------------------
2319  // Assign the data server and the load balancer
2320  //--------------------------------------------------------------------------
2321  std::string lastServer = pFileUrl->GetHostId();
2322  if( hostList )
2323  {
2324  delete pDataServer;
2325  delete pLoadBalancer;
2326  pLoadBalancer = 0;
2327  delete pWrtRecoveryRedir;
2328  pWrtRecoveryRedir = 0;
2329 
2330  pDataServer = new URL( hostList->back().url );
2331  pDataServer->SetParams( pFileUrl->GetParams() );
2332  if( !( pUseVirtRedirector && pFileUrl->IsMetalink() ) ) pDataServer->SetPath( pFileUrl->GetPath() );
2333  lastServer = pDataServer->GetHostId();
2334  HostList::const_iterator itC;
2335  URL::ParamsMap params = pDataServer->GetParams();
2336  for( itC = hostList->begin(); itC != hostList->end(); ++itC )
2337  {
2338  MessageUtils::MergeCGI( params,
2339  itC->url.GetParams(),
2340  true );
2341  }
2342  pDataServer->SetParams( params );
2343 
2344  HostList::const_reverse_iterator it;
2345  for( it = hostList->rbegin(); it != hostList->rend(); ++it )
2346  if( it->loadBalancer )
2347  {
2348  pLoadBalancer = new URL( it->url );
2349  break;
2350  }
2351 
2352  for( it = hostList->rbegin(); it != hostList->rend(); ++it )
2353  if( it->flags & kXR_recoverWrts )
2354  {
2355  pWrtRecoveryRedir = new URL( it->url );
2356  break;
2357  }
2358  }
2359 
2360  log->Debug( FileMsg, "[0x%x@%s] Open has returned with status %s",
2361  this, pFileUrl->GetURL().c_str(), status->ToStr().c_str() );
2362 
2363  if( pDataServer && !pDataServer->IsLocalFile() )
2364  {
2365  //------------------------------------------------------------------------
2366  // Check if we are using a secure connection
2367  //------------------------------------------------------------------------
2368  XrdCl::AnyObject isencobj;
2370  QueryTransport( *pDataServer, XRootDQuery::IsEncrypted, isencobj );
2371  if( st.IsOK() )
2372  {
2373  bool *isenc;
2374  isencobj.Get( isenc );
2375  pIsChannelEncrypted = *isenc;
2376  delete isenc;
2377  }
2378  }
2379 
2380  //--------------------------------------------------------------------------
2381  // We have failed
2382  //--------------------------------------------------------------------------
2383  pStatus = *status;
2384  if( !pStatus.IsOK() || !openInfo )
2385  {
2386  log->Debug( FileMsg, "[0x%x@%s] Error while opening at %s: %s",
2387  this, pFileUrl->GetURL().c_str(), lastServer.c_str(),
2388  pStatus.ToStr().c_str() );
2389  FailQueuedMessages( pStatus );
2390  pFileState = Error;
2391 
2392  //------------------------------------------------------------------------
2393  // Report to monitoring
2394  //------------------------------------------------------------------------
2396  if( mon )
2397  {
2399  i.file = pFileUrl;
2400  i.status = status;
2402  mon->Event( Monitor::EvErrIO, &i );
2403  }
2404  }
2405  //--------------------------------------------------------------------------
2406  // We have succeeded
2407  //--------------------------------------------------------------------------
2408  else
2409  {
2410  //------------------------------------------------------------------------
2411  // Store the response info
2412  //------------------------------------------------------------------------
2413  openInfo->GetFileHandle( pFileHandle );
2414  pSessionId = openInfo->GetSessionId();
2415  if( openInfo->GetStatInfo() )
2416  {
2417  delete pStatInfo;
2418  pStatInfo = new StatInfo( *openInfo->GetStatInfo() );
2419  }
2420 
2421  log->Debug( FileMsg, "[0x%x@%s] successfully opened at %s, handle: 0x%x, "
2422  "session id: %ld", this, pFileUrl->GetURL().c_str(),
2423  pDataServer->GetHostId().c_str(), *((uint32_t*)pFileHandle),
2424  pSessionId );
2425 
2426  //------------------------------------------------------------------------
2427  // Inform the monitoring about opening success
2428  //------------------------------------------------------------------------
2429  gettimeofday( &pOpenTime, 0 );
2431  if( mon )
2432  {
2434  i.file = pFileUrl;
2435  i.dataServer = pDataServer->GetHostId();
2436  i.oFlags = pOpenFlags;
2437  i.fSize = pStatInfo ? pStatInfo->GetSize() : 0;
2438  mon->Event( Monitor::EvOpen, &i );
2439  }
2440 
2441  //------------------------------------------------------------------------
2442  // Resend the queued messages if any
2443  //------------------------------------------------------------------------
2444  ReSendQueuedMessages();
2445  pFileState = Opened;
2446  }
2447  }
#define kXR_recoverWrts
Definition: XProtocol.hh:1163
void Get(Type &object)
Retrieve the object being held.
static Monitor * GetMonitor()
Get the monitor object.
static void MergeCGI(URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
Merge cgi2 into cgi1.
An abstract class to describe the client-side monitoring plugin interface.
Definition: XrdClMonitor.hh:56
@ EvErrIO
ErrorInfo: An I/O error occurred.
@ EvOpen
OpenInfo: File opened.
virtual void Event(EventCode evCode, void *evData)=0
void GetFileHandle(uint8_t *fileHandle) const
Get the file handle (4bytes)
const StatInfo * GetStatInfo() const
Get the stat info.
uint64_t GetSessionId() const
Object stat info.
uint64_t GetSize() const
Get size (in bytes)
URL representation.
Definition: XrdClURL.hh:31
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
void SetParams(const std::string &params)
Set params.
Definition: XrdClURL.cc:388
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:220
const ParamsMap & GetParams() const
Get the URL params.
Definition: XrdClURL.hh:239
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:212
Describe an encountered file-based error.
const XRootDStatus * status
Status code.
const URL * file
The file in question.
Operation opCode
The associated operation.
Describe a file open event to the monitor.
uint64_t fSize
File size in bytes.
const URL * file
File in question.
std::string dataServer
Actual fata server.
uint16_t oFlags
OpenFlags.
static const uint16_t IsEncrypted
returns true if the channel is encrypted

References XrdCl::Monitor::OpenInfo::dataServer, XrdCl::Log::Debug(), XrdCl::Monitor::ErrorInfo::ErrOpen, Error, XrdCl::Monitor::Event(), XrdCl::Monitor::EvErrIO, XrdCl::Monitor::EvOpen, XrdCl::Monitor::OpenInfo::file, XrdCl::Monitor::ErrorInfo::file, XrdCl::FileMsg, XrdCl::Monitor::OpenInfo::fSize, XrdCl::AnyObject::Get(), XrdCl::OpenInfo::GetFileHandle(), XrdCl::URL::GetHostId(), XrdCl::DefaultEnv::GetLog(), XrdCl::DefaultEnv::GetMonitor(), XrdCl::URL::GetParams(), XrdCl::URL::GetPath(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::OpenInfo::GetSessionId(), XrdCl::StatInfo::GetSize(), XrdCl::OpenInfo::GetStatInfo(), XrdCl::URL::GetURL(), XrdCl::XRootDQuery::IsEncrypted, XrdCl::URL::IsLocalFile(), XrdCl::URL::IsMetalink(), XrdCl::Status::IsOK(), kXR_recoverWrts, XrdCl::MessageUtils::MergeCGI(), XrdCl::Monitor::OpenInfo::oFlags, XrdCl::Monitor::ErrorInfo::opCode, Opened, XrdCl::URL::SetParams(), XrdCl::URL::SetPath(), XrdCl::Monitor::ErrorInfo::status, and XrdCl::XRootDStatus::ToStr().

+ Here is the call graph for this function:

◆ OnStateError()

void XrdCl::FileStateHandler::OnStateError ( std::shared_ptr< FileStateHandler > &  self,
XRootDStatus status,
Message message,
ResponseHandler userHandler,
MessageSendParams sendParams 
)
static

Handle an error while sending a stateful message.

Definition at line 2475 of file XrdClFileStateHandler.cc.

2480  {
2481  //--------------------------------------------------------------------------
2482  // It may be a redirection
2483  //--------------------------------------------------------------------------
2484  if( !status->IsOK() && status->code == errRedirect && self->pFollowRedirects )
2485  {
2486  static const std::string root = "root", xroot = "xroot", file = "file",
2487  roots = "roots", xroots = "xroots";
2488  std::string msg = status->GetErrorMessage();
2489  if( !msg.compare( 0, root.size(), root ) ||
2490  !msg.compare( 0, xroot.size(), xroot ) ||
2491  !msg.compare( 0, file.size(), file ) ||
2492  !msg.compare( 0, roots.size(), roots ) ||
2493  !msg.compare( 0, xroots.size(), xroots ) )
2494  {
2495  FileStateHandler::OnStateRedirection( self, msg, message, userHandler, sendParams );
2496  return;
2497  }
2498  }
2499 
2500  //--------------------------------------------------------------------------
2501  // Handle error
2502  //--------------------------------------------------------------------------
2503  Log *log = DefaultEnv::GetLog();
2504  XrdSysMutexHelper scopedLock( self->pMutex );
2505  self->pInTheFly.erase( message );
2506 
2507  log->Dump( FileMsg, "[0x%x@%s] File state error encountered. Message %s "
2508  "returned with %s", self.get(), self->pFileUrl->GetURL().c_str(),
2509  message->GetDescription().c_str(), status->ToStr().c_str() );
2510 
2511  //--------------------------------------------------------------------------
2512  // Report to monitoring
2513  //--------------------------------------------------------------------------
2515  if( mon )
2516  {
2518  i.file = self->pFileUrl;
2519  i.status = status;
2520 
2521  ClientRequest *req = (ClientRequest*)message->GetBuffer();
2522  switch( req->header.requestid )
2523  {
2524  case kXR_read: i.opCode = Monitor::ErrorInfo::ErrRead; break;
2530  default: i.opCode = Monitor::ErrorInfo::ErrUnc;
2531  }
2532 
2533  mon->Event( Monitor::EvErrIO, &i );
2534  }
2535 
2536  //--------------------------------------------------------------------------
2537  // The message is not recoverable
2538  // (message using a kernel buffer is not recoverable by definition)
2539  //--------------------------------------------------------------------------
2540  if( !self->IsRecoverable( *status ) || sendParams.kbuff )
2541  {
2542  log->Error( FileMsg, "[0x%x@%s] Fatal file state error. Message %s "
2543  "returned with %s", self.get(), self->pFileUrl->GetURL().c_str(),
2544  message->GetDescription().c_str(), status->ToStr().c_str() );
2545 
2546  self->FailMessage( RequestData( message, userHandler, sendParams ), *status );
2547  delete status;
2548  return;
2549  }
2550 
2551  //--------------------------------------------------------------------------
2552  // Insert the message to the recovery queue and start the recovery
2553  // procedure if we don't have any more message in the fly
2554  //--------------------------------------------------------------------------
2555  self->pCloseReason = *status;
2556  RecoverMessage( self, RequestData( message, userHandler, sendParams ) );
2557  delete status;
2558  }
struct ClientRequestHdr header
Definition: XProtocol.hh:844
kXR_unt16 requestid
Definition: XProtocol.hh:157
@ kXR_read
Definition: XProtocol.hh:125
@ kXR_writev
Definition: XProtocol.hh:143
@ kXR_readv
Definition: XProtocol.hh:137
@ kXR_pgread
Definition: XProtocol.hh:142
@ kXR_pgwrite
Definition: XProtocol.hh:138
static void OnStateRedirection(std::shared_ptr< FileStateHandler > &self, const std::string &redirectUrl, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle stateful redirect.
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
const std::string & GetDescription() const
Get the description of the message.
Definition: XrdClMessage.hh:95
const std::string & GetErrorMessage() const
Get error message.
const uint16_t errRedirect
Definition: XrdClStatus.hh:106
XrdSys::KernelBuffer * kbuff
@ ErrUnc
Unclassified operation.

References XrdCl::Status::code, XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::Monitor::ErrorInfo::ErrRead, XrdCl::Monitor::ErrorInfo::ErrReadV, XrdCl::errRedirect, XrdCl::Monitor::ErrorInfo::ErrUnc, XrdCl::Monitor::ErrorInfo::ErrWrite, XrdCl::Monitor::ErrorInfo::ErrWriteV, XrdCl::Monitor::Event(), XrdCl::Monitor::EvErrIO, XrdCl::Monitor::ErrorInfo::file, XrdCl::FileMsg, XrdCl::Buffer::GetBuffer(), XrdCl::Message::GetDescription(), XrdCl::XRootDStatus::GetErrorMessage(), XrdCl::DefaultEnv::GetLog(), XrdCl::DefaultEnv::GetMonitor(), ClientRequest::header, XrdCl::Status::IsOK(), XrdCl::MessageSendParams::kbuff, kXR_pgread, kXR_pgwrite, kXR_read, kXR_readv, kXR_write, kXR_writev, OnStateRedirection(), XrdCl::Monitor::ErrorInfo::opCode, ClientRequestHdr::requestid, XrdCl::Monitor::ErrorInfo::status, and XrdCl::XRootDStatus::ToStr().

+ Here is the call graph for this function:

◆ OnStateRedirection()

void XrdCl::FileStateHandler::OnStateRedirection ( std::shared_ptr< FileStateHandler > &  self,
const std::string &  redirectUrl,
Message message,
ResponseHandler userHandler,
MessageSendParams sendParams 
)
static

Handle stateful redirect.

Definition at line 2563 of file XrdClFileStateHandler.cc.

2568  {
2569  XrdSysMutexHelper scopedLock( self->pMutex );
2570  self->pInTheFly.erase( message );
2571 
2572  //--------------------------------------------------------------------------
2573  // Register the state redirect url and append the new cgi information to
2574  // the file URL
2575  //--------------------------------------------------------------------------
2576  if( !self->pStateRedirect )
2577  {
2578  std::ostringstream o;
2579  self->pStateRedirect = new URL( redirectUrl );
2580  URL::ParamsMap params = self->pFileUrl->GetParams();
2581  MessageUtils::MergeCGI( params,
2582  self->pStateRedirect->GetParams(),
2583  false );
2584  self->pFileUrl->SetParams( params );
2585  }
2586 
2587  RecoverMessage( self, RequestData( message, userHandler, sendParams ) );
2588  }

References XrdCl::MessageUtils::MergeCGI().

Referenced by OnStateError().

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

◆ OnStateResponse()

void XrdCl::FileStateHandler::OnStateResponse ( std::shared_ptr< FileStateHandler > &  self,
XRootDStatus status,
Message message,
AnyObject response,
HostList hostList 
)
static

Handle stateful response.

Definition at line 2593 of file XrdClFileStateHandler.cc.

2598  {
2599  Log *log = DefaultEnv::GetLog();
2600  XrdSysMutexHelper scopedLock( self->pMutex );
2601 
2602  log->Dump( FileMsg, "[0x%x@%s] Got state response for message %s",
2603  self.get(), self->pFileUrl->GetURL().c_str(),
2604  message->GetDescription().c_str() );
2605 
2606  //--------------------------------------------------------------------------
2607  // Since this message may be the last "in-the-fly" and no recovery
2608  // is done if messages are in the fly, we may need to trigger recovery
2609  //--------------------------------------------------------------------------
2610  self->pInTheFly.erase( message );
2611  RunRecovery( self );
2612 
2613  //--------------------------------------------------------------------------
2614  // Play with the actual response before returning it. This is a good
2615  // place to do caching in the future.
2616  //--------------------------------------------------------------------------
2617  ClientRequest *req = (ClientRequest*)message->GetBuffer();
2618  switch( req->header.requestid )
2619  {
2620  //------------------------------------------------------------------------
2621  // Cache the stat response
2622  //------------------------------------------------------------------------
2623  case kXR_stat:
2624  {
2625  StatInfo *info = 0;
2626  response->Get( info );
2627  delete self->pStatInfo;
2628  self->pStatInfo = new StatInfo( *info );
2629  break;
2630  }
2631 
2632  //------------------------------------------------------------------------
2633  // Handle read response
2634  //------------------------------------------------------------------------
2635  case kXR_read:
2636  {
2637  ++self->pRCount;
2638  self->pRBytes += req->read.rlen;
2639  break;
2640  }
2641 
2642  //------------------------------------------------------------------------
2643  // Handle read response
2644  //------------------------------------------------------------------------
2645  case kXR_pgread:
2646  {
2647  ++self->pRCount;
2648  self->pRBytes += req->pgread.rlen;
2649  break;
2650  }
2651 
2652  //------------------------------------------------------------------------
2653  // Handle readv response
2654  //------------------------------------------------------------------------
2655  case kXR_readv:
2656  {
2657  ++self->pVRCount;
2658  size_t segs = req->header.dlen/sizeof(readahead_list);
2659  readahead_list *dataChunk = (readahead_list*)message->GetBuffer( 24 );
2660  for( size_t i = 0; i < segs; ++i )
2661  self->pVRBytes += dataChunk[i].rlen;
2662  self->pVSegs += segs;
2663  break;
2664  }
2665 
2666  //------------------------------------------------------------------------
2667  // Handle write response
2668  //------------------------------------------------------------------------
2669  case kXR_write:
2670  {
2671  ++self->pWCount;
2672  self->pWBytes += req->write.dlen;
2673  break;
2674  }
2675 
2676  //------------------------------------------------------------------------
2677  // Handle write response
2678  //------------------------------------------------------------------------
2679  case kXR_pgwrite:
2680  {
2681  ++self->pWCount;
2682  self->pWBytes += req->pgwrite.dlen;
2683  break;
2684  }
2685 
2686  //------------------------------------------------------------------------
2687  // Handle writev response
2688  //------------------------------------------------------------------------
2689  case kXR_writev:
2690  {
2691  ++self->pVWCount;
2692  size_t size = req->header.dlen/sizeof(readahead_list);
2693  XrdProto::write_list *wrtList =
2694  reinterpret_cast<XrdProto::write_list*>( message->GetBuffer( 24 ) );
2695  for( size_t i = 0; i < size; ++i )
2696  self->pVWBytes += wrtList[i].wlen;
2697  break;
2698  }
2699  };
2700  }
struct ClientPgReadRequest pgread
Definition: XProtocol.hh:859
struct ClientPgWriteRequest pgwrite
Definition: XProtocol.hh:860
@ kXR_stat
Definition: XProtocol.hh:129
struct ClientReadRequest read
Definition: XProtocol.hh:865
struct ClientWriteRequest write
Definition: XProtocol.hh:874
kXR_int32 rlen
Definition: XProtocol.hh:647
kXR_int32 dlen
Definition: XProtocol.hh:159

References ClientRequestHdr::dlen, ClientPgWriteRequest::dlen, ClientWriteRequest::dlen, XrdCl::Log::Dump(), XrdCl::FileMsg, XrdCl::AnyObject::Get(), XrdCl::Buffer::GetBuffer(), XrdCl::Message::GetDescription(), XrdCl::DefaultEnv::GetLog(), ClientRequest::header, kXR_pgread, kXR_pgwrite, kXR_read, kXR_readv, kXR_stat, kXR_write, kXR_writev, ClientRequest::pgread, ClientRequest::pgwrite, ClientRequest::read, ClientRequestHdr::requestid, ClientPgReadRequest::rlen, ClientReadRequest::rlen, readahead_list::rlen, XrdProto::write_list::wlen, and ClientRequest::write.

+ Here is the call graph for this function:

◆ Open()

XRootDStatus XrdCl::FileStateHandler::Open ( std::shared_ptr< FileStateHandler > &  self,
const std::string &  url,
uint16_t  flags,
uint16_t  mode,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Open the file pointed to by the given URL

Parameters
urlurl of the file to be opened
flagsOpenFlags::Flags
modeAccess::Mode for new files, 0 otherwise
handlerhandler to be notified about the status of the operation
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 746 of file XrdClFileStateHandler.cc.

752  {
753  XrdSysMutexHelper scopedLock( self->pMutex );
754 
755  //--------------------------------------------------------------------------
756  // Check if we can proceed
757  //--------------------------------------------------------------------------
758  if( self->pFileState == Error )
759  return self->pStatus;
760 
761  if( self->pFileState == OpenInProgress )
763 
764  if( self->pFileState == CloseInProgress || self->pFileState == Opened ||
765  self->pFileState == Recovering )
766  return XRootDStatus( stError, errInvalidOp );
767 
768  self->pFileState = OpenInProgress;
769 
770  //--------------------------------------------------------------------------
771  // Check if the parameters are valid
772  //--------------------------------------------------------------------------
773  Log *log = DefaultEnv::GetLog();
774 
775  if( self->pFileUrl )
776  {
777  if( self->pUseVirtRedirector && self->pFileUrl->IsMetalink() )
778  {
780  registry.Release( *self->pFileUrl );
781  }
782  delete self->pFileUrl;
783  self->pFileUrl = 0;
784  }
785 
786  self->pFileUrl = new URL( url );
787 
788  //--------------------------------------------------------------------------
789  // Add unique uuid to each open request so replays due to error/timeout
790  // recovery can be correctly handled.
791  //--------------------------------------------------------------------------
792  URL::ParamsMap cgi = self->pFileUrl->GetParams();
793  uuid_t uuid;
794  char requuid[37]= {0};
795  uuid_generate( uuid );
796  uuid_unparse( uuid, requuid );
797  cgi["xrdcl.requuid"] = requuid;
798  self->pFileUrl->SetParams( cgi );
799 
800  if( !self->pFileUrl->IsValid() )
801  {
802  log->Error( FileMsg, "[0x%x@%s] Trying to open invalid url: %s",
803  self.get(), self->pFileUrl->GetPath().c_str(), url.c_str() );
804  self->pStatus = XRootDStatus( stError, errInvalidArgs );
805  self->pFileState = Closed;
806  return self->pStatus;
807  }
808 
809  //--------------------------------------------------------------------------
810  // Check if the recovery procedures should be enabled
811  //--------------------------------------------------------------------------
812  const URL::ParamsMap &urlParams = self->pFileUrl->GetParams();
813  URL::ParamsMap::const_iterator it;
814  it = urlParams.find( "xrdcl.recover-reads" );
815  if( (it != urlParams.end() && it->second == "false") ||
816  !self->pDoRecoverRead )
817  {
818  self->pDoRecoverRead = false;
819  log->Debug( FileMsg, "[0x%x@%s] Read recovery procedures are disabled",
820  self.get(), self->pFileUrl->GetURL().c_str() );
821  }
822 
823  it = urlParams.find( "xrdcl.recover-writes" );
824  if( (it != urlParams.end() && it->second == "false") ||
825  !self->pDoRecoverWrite )
826  {
827  self->pDoRecoverWrite = false;
828  log->Debug( FileMsg, "[0x%x@%s] Write recovery procedures are disabled",
829  self.get(), self->pFileUrl->GetURL().c_str() );
830  }
831 
832  //--------------------------------------------------------------------------
833  // Open the file
834  //--------------------------------------------------------------------------
835  log->Debug( FileMsg, "[0x%x@%s] Sending an open command", self.get(),
836  self->pFileUrl->GetURL().c_str() );
837 
838  self->pOpenMode = mode;
839  self->pOpenFlags = flags;
840  OpenHandler *openHandler = new OpenHandler( self, handler );
841 
842  Message *msg;
843  ClientOpenRequest *req;
844  std::string path = self->pFileUrl->GetPathWithFilteredParams();
845  MessageUtils::CreateRequest( msg, req, path.length() );
846 
847  req->requestid = kXR_open;
848  req->mode = mode;
849  req->options = flags | kXR_async | kXR_retstat;
850  req->dlen = path.length();
851  msg->Append( path.c_str(), path.length(), 24 );
852 
854  MessageSendParams params; params.timeout = timeout;
855  params.followRedirects = self->pFollowRedirects;
857 
858  XRootDStatus st = self->IssueRequest( *self->pFileUrl, msg, openHandler, params );
859 
860  if( !st.IsOK() )
861  {
862  delete openHandler;
863  self->pStatus = st;
864  self->pFileState = Closed;
865  return st;
866  }
867  return st;
868  }
kXR_unt16 requestid
Definition: XProtocol.hh:479
kXR_unt16 options
Definition: XProtocol.hh:481
@ kXR_async
Definition: XProtocol.hh:458
@ kXR_retstat
Definition: XProtocol.hh:463
@ kXR_open
Definition: XProtocol.hh:122
kXR_int32 dlen
Definition: XProtocol.hh:483
kXR_unt16 mode
Definition: XProtocol.hh:480
const uint16_t errInvalidArgs
Definition: XrdClStatus.hh:58

References XrdCl::Buffer::Append(), Closed, CloseInProgress, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientOpenRequest::dlen, XrdCl::errInProgress, XrdCl::errInvalidArgs, XrdCl::errInvalidOp, Error, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), XrdCl::RedirectorRegistry::Instance(), XrdCl::Status::IsOK(), kXR_async, kXR_open, kXR_retstat, ClientOpenRequest::mode, Opened, OpenInProgress, ClientOpenRequest::options, XrdCl::MessageUtils::ProcessSendParams(), Recovering, XrdCl::RedirectorRegistry::Release(), ClientOpenRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Open().

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

◆ PgRead()

XRootDStatus XrdCl::FileStateHandler::PgRead ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Read data pages at a given offset

Parameters
offset: offset from the beginning of the file (Note: has to 4KB aligned)
size: buffer size
buffer: a pointer to buffer big enough to hold the data
handler: handler to be notified when the response arrives, the response parameter will hold a PgReadInfo object if the procedure was successful
timeout: timeout value, if 0 environment default will be used
Returns
: status of the operation

Definition at line 1054 of file XrdClFileStateHandler.cc.

1060  {
1061  int issupported = true;
1062  AnyObject obj;
1064  int protver = 0;
1065  XRootDStatus st2 = Utils::GetProtocolVersion( *self->pDataServer, protver );
1066  if( st1.IsOK() && st2.IsOK() )
1067  {
1068  int *ptr = 0;
1069  obj.Get( ptr );
1070  issupported = ( *ptr & kXR_suppgrw ) && ( protver >= kXR_PROTPGRWVERSION );
1071  delete ptr;
1072  }
1073  else
1074  issupported = false;
1075 
1076  if( !issupported )
1077  {
1078  DefaultEnv::GetLog()->Debug( FileMsg, "[0x%x@%s] PgRead not supported; substituting with Read.",
1079  self.get(), self->pFileUrl->GetURL().c_str() );
1080  ResponseHandler *substitHandler = new PgReadSubstitutionHandler( self, handler );
1081  auto st = Read( self, offset, size, buffer, substitHandler, timeout );
1082  if( !st.IsOK() ) delete substitHandler;
1083  return st;
1084  }
1085 
1086  ResponseHandler* pgHandler = new PgReadHandler( self, handler, offset );
1087  auto st = PgReadImpl( self, offset, size, buffer, PgReadFlags::None, pgHandler, timeout );
1088  if( !st.IsOK() ) delete pgHandler;
1089  return st;
1090  }
#define kXR_suppgrw
Definition: XProtocol.hh:1171
#define kXR_PROTPGRWVERSION
Definition: XProtocol.hh:73
static XRootDStatus PgReadImpl(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, uint16_t flags, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Read(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
Status QueryTransport(const URL &url, uint16_t query, AnyObject &result)
Handle an async response.
static XrdCl::XRootDStatus GetProtocolVersion(const XrdCl::URL url, int &protver)
Definition: XrdClUtils.hh:235
static const uint16_t ServerFlags
returns server flags

References XrdCl::Log::Debug(), XrdCl::FileMsg, XrdCl::AnyObject::Get(), XrdCl::DefaultEnv::GetLog(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::Utils::GetProtocolVersion(), XrdCl::Status::IsOK(), kXR_PROTPGRWVERSION, kXR_suppgrw, XrdCl::PgReadFlags::None, PgReadImpl(), XrdCl::PostMaster::QueryTransport(), Read(), and XrdCl::XRootDQuery::ServerFlags.

Referenced by XrdCl::File::PgRead().

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

◆ PgReadImpl()

XRootDStatus XrdCl::FileStateHandler::PgReadImpl ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
void *  buffer,
uint16_t  flags,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Read data pages at a given offset (actual implementation)

Parameters
offset: offset from the beginning of the file (Note: has to 4KB aligned)
size: buffer size
buffer: a pointer to buffer big enough to hold the data
flags: PgRead flags
handler: handler to be notified when the response arrives, the response parameter will hold a PgReadInfo object if the procedure was successful
timeout: timeout value, if 0 environment default will be used
Returns
: status of the operation

Definition at line 1110 of file XrdClFileStateHandler.cc.

1117  {
1118  XrdSysMutexHelper scopedLock( self->pMutex );
1119 
1120  if( self->pFileState == Error ) return self->pStatus;
1121 
1122  if( self->pFileState != Opened && self->pFileState != Recovering )
1123  return XRootDStatus( stError, errInvalidOp );
1124 
1125  Log *log = DefaultEnv::GetLog();
1126  log->Debug( FileMsg, "[0x%x@%s] Sending a pgread command for handle 0x%x to "
1127  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1128  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1129 
1130  Message *msg;
1131  ClientPgReadRequest *req;
1132  MessageUtils::CreateRequest( msg, req, sizeof( ClientPgReadReqArgs ) );
1133 
1134  req->requestid = kXR_pgread;
1135  req->offset = offset;
1136  req->rlen = size;
1137  memcpy( req->fhandle, self->pFileHandle, 4 );
1138 
1139  //--------------------------------------------------------------------------
1140  // Now adjust the message size so it can hold PgRead arguments
1141  //--------------------------------------------------------------------------
1142  req->dlen = sizeof( ClientPgReadReqArgs );
1143  void *newBuf = msg->GetBuffer( sizeof( ClientPgReadRequest ) );
1144  memset( newBuf, 0, sizeof( ClientPgReadReqArgs ) );
1145  ClientPgReadReqArgs *args = reinterpret_cast<ClientPgReadReqArgs*>(
1146  msg->GetBuffer( sizeof( ClientPgReadRequest ) ) );
1147  args->reqflags = flags;
1148 
1149  ChunkList *list = new ChunkList();
1150  list->push_back( ChunkInfo( offset, size, buffer ) );
1151 
1153  MessageSendParams params;
1154  params.timeout = timeout;
1155  params.followRedirects = false;
1156  params.stateful = true;
1157  params.chunkList = list;
1159  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1160 
1161  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1162  }
kXR_char fhandle[4]
Definition: XProtocol.hh:509
kXR_unt16 requestid
Definition: XProtocol.hh:508

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientPgReadRequest::dlen, XrdCl::errInvalidOp, Error, ClientPgReadRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetLog(), kXR_pgread, ClientPgReadRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientPgReadReqArgs::reqflags, ClientPgReadRequest::requestid, ClientPgReadRequest::rlen, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by PgRead(), and PgReadRetry().

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

◆ PgReadRetry()

XRootDStatus XrdCl::FileStateHandler::PgReadRetry ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
size_t  pgnb,
void *  buffer,
PgReadHandler *  handler,
uint16_t  timeout = 0 
)
static

Retry reading one page of data at a given offset

Parameters
offset: offset from the beginning of the file (Note: has to 4KB aligned)
size: buffer size
buffer: a pointer to buffer big enough to hold the data
handler: handler to be notified when the response arrives
timeout: timeout value, if 0 environment default will be used
Returns
: status of the operation

Definition at line 1092 of file XrdClFileStateHandler.cc.

1099  {
1100  if( size > (uint32_t)XrdSys::PageSize )
1101  return XRootDStatus( stError, errInvalidArgs, EINVAL,
1102  "PgRead retry size exceeded 4KB." );
1103 
1104  ResponseHandler *retryHandler = new PgReadRetryHandler( handler, pgnb );
1105  XRootDStatus st = PgReadImpl( self, offset, size, buffer, PgReadFlags::Retry, retryHandler, timeout );
1106  if( !st.IsOK() ) delete retryHandler;
1107  return st;
1108  }
static const int PageSize

References XrdCl::errInvalidArgs, XrdCl::Status::IsOK(), XrdSys::PageSize, PgReadImpl(), XrdCl::PgReadFlags::Retry, and XrdCl::stError.

+ Here is the call graph for this function:

◆ PgWrite()

XRootDStatus XrdCl::FileStateHandler::PgWrite ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
const void *  buffer,
std::vector< uint32_t > &  cksums,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write number of pages at a given offset - async

Parameters
offsetoffset from the beginning of the file
sizebuffer size
buffera pointer to a buffer holding data pages
cksumsthe crc32c checksums for each 4KB page
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1291 of file XrdClFileStateHandler.cc.

1298  {
1299  //--------------------------------------------------------------------------
1300  // Resolve timeout value
1301  //--------------------------------------------------------------------------
1302  if( timeout == 0 )
1303  {
1304  int val = DefaultRequestTimeout;
1305  XrdCl::DefaultEnv::GetEnv()->GetInt( "RequestTimeout", val );
1306  timeout = val;
1307  }
1308 
1309  //--------------------------------------------------------------------------
1310  // Validate the digest vector size
1311  //--------------------------------------------------------------------------
1312  if( cksums.empty() )
1313  {
1314  const char *data = static_cast<const char*>( buffer );
1315  XrdOucPgrwUtils::csCalc( data, offset, size, cksums );
1316  }
1317  else
1318  {
1319  size_t crc32cCnt = XrdOucPgrwUtils::csNum( offset, size );
1320  if( crc32cCnt != cksums.size() )
1321  return XRootDStatus( stError, errInvalidArgs, 0, "Wrong number of crc32c digests." );
1322  }
1323 
1324  //--------------------------------------------------------------------------
1325  // Create a context for PgWrite operation
1326  //--------------------------------------------------------------------------
1327  struct pgwrt_t
1328  {
1329  pgwrt_t( ResponseHandler *h ) : handler( h ), status( nullptr )
1330  {
1331  }
1332 
1333  ~pgwrt_t()
1334  {
1335  if( handler )
1336  {
1337  // if all retries were successful no error status was set
1338  if( !status ) status = new XRootDStatus();
1339  handler->HandleResponse( status, nullptr );
1340  }
1341  }
1342 
1343  static size_t GetPgNb( uint64_t pgoff, uint64_t offset, uint32_t fstpglen )
1344  {
1345  if( pgoff == offset ) return 0; // we need this if statement because we operate on unsigned integers
1346  return ( pgoff - ( offset + fstpglen ) ) / XrdSys::PageSize + 1;
1347  }
1348 
1349  inline void SetStatus( XRootDStatus* s )
1350  {
1351  if( !status ) status = s;
1352  else delete s;
1353  }
1354 
1355  ResponseHandler *handler;
1356  XRootDStatus *status;
1357  };
1358  auto pgwrt = std::make_shared<pgwrt_t>( handler );
1359 
1360  int fLen, lLen;
1361  XrdOucPgrwUtils::csNum( offset, size, fLen, lLen );
1362  uint32_t fstpglen = fLen;
1363 
1364  time_t start = ::time( nullptr );
1365  auto h = ResponseHandler::Wrap( [=]( XrdCl::XRootDStatus *s, XrdCl::AnyObject *r ) mutable
1366  {
1367  std::unique_ptr<AnyObject> scoped( r );
1368  // if the request failed simply pass the status to the
1369  // user handler
1370  if( !s->IsOK() )
1371  {
1372  pgwrt->SetStatus( s );
1373  return; // pgwrt destructor will call the handler
1374  }
1375  // also if the request was sucessful and there were no
1376  // corrupted pages pass the status to the user handler
1377  RetryInfo *inf = nullptr;
1378  r->Get( inf );
1379  if( !inf->NeedRetry() )
1380  {
1381  pgwrt->SetStatus( s );
1382  return; // pgwrt destructor will call the handler
1383  }
1384  delete s;
1385  // first adjust the timeout value
1386  uint16_t elapsed = ::time( nullptr ) - start;
1387  if( elapsed >= timeout )
1388  {
1389  pgwrt->SetStatus( new XRootDStatus( stError, errOperationExpired ) );
1390  return; // pgwrt destructor will call the handler
1391  }
1392  else timeout -= elapsed;
1393  // retransmit the corrupted pages
1394  for( size_t i = 0; i < inf->Size(); ++i )
1395  {
1396  auto tpl = inf->At( i );
1397  uint64_t pgoff = std::get<0>( tpl );
1398  uint32_t pglen = std::get<1>( tpl );
1399  const void *pgbuf = static_cast<const char*>( buffer ) + ( pgoff - offset );
1400  uint32_t pgdigest = cksums[pgwrt_t::GetPgNb( pgoff, offset, fstpglen )];
1401  auto h = ResponseHandler::Wrap( [=]( XrdCl::XRootDStatus *s, XrdCl::AnyObject *r ) mutable
1402  {
1403  std::unique_ptr<AnyObject> scoped( r );
1404  // if we failed simply set the status
1405  if( !s->IsOK() )
1406  {
1407  pgwrt->SetStatus( s );
1408  return; // the destructor will call the handler
1409  }
1410  delete s;
1411  // otherwise check if the data were not corrupted again
1412  RetryInfo *inf = nullptr;
1413  r->Get( inf );
1414  if( inf->NeedRetry() ) // so we failed in the end
1415  {
1416  DefaultEnv::GetLog()->Warning( FileMsg, "[0x%x@%s] Failed retransmitting corrupted "
1417  "page: pgoff=%llu, pglen=%du, pgdigest=%du", self.get(),
1418  self->pFileUrl->GetURL().c_str(), pgoff, pglen, pgdigest );
1419  pgwrt->SetStatus( new XRootDStatus( stError, errDataError, 0,
1420  "Failed to retransmit corrupted page" ) );
1421  }
1422  else
1423  DefaultEnv::GetLog()->Info( FileMsg, "[0x%x@%s] Succesfuly retransmitted corrupted "
1424  "page: pgoff=%llu, pglen=%du, pgdigest=%du", self.get(),
1425  self->pFileUrl->GetURL().c_str(), pgoff, pglen, pgdigest );
1426  } );
1427  auto st = PgWriteRetry( self, pgoff, pglen, pgbuf, pgdigest, h, timeout );
1428  if( !st.IsOK() ) pgwrt->SetStatus( new XRootDStatus( st ) );
1429  DefaultEnv::GetLog()->Info( FileMsg, "[0x%x@%s] Retransmitting corrupted page: "
1430  "pgoff=%llu, pglen=%du, pgdigest=%du", self.get(),
1431  self->pFileUrl->GetURL().c_str(), pgoff, pglen, pgdigest );
1432  }
1433  } );
1434 
1435  auto st = PgWriteImpl( self, offset, size, buffer, cksums, 0, h, timeout );
1436  if( !st.IsOK() )
1437  {
1438  pgwrt->handler = nullptr;
1439  delete h;
1440  }
1441  return st;
1442  }
static Env * GetEnv()
Get default client environment.
bool GetInt(const std::string &key, int &value)
Definition: XrdClEnv.cc:89
static XRootDStatus PgWriteImpl(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, kXR_char flags, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus PgWriteRetry(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, uint32_t digest, ResponseHandler *handler, uint16_t timeout=0)
void Warning(uint64_t topic, const char *format,...)
Report a warning.
Definition: XrdClLog.cc:248
void Info(uint64_t topic, const char *format,...)
Print an info.
Definition: XrdClLog.cc:265
static ResponseHandler * Wrap(std::function< void(XRootDStatus &, AnyObject &)> func)
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
const uint16_t errOperationExpired
Definition: XrdClStatus.hh:90
const uint16_t errDataError
data is corrupted
Definition: XrdClStatus.hh:63
const int DefaultRequestTimeout
std::tuple< uint64_t, uint32_t > At(size_t i)

References XrdCl::RetryInfo::At(), XrdOucPgrwUtils::csCalc(), XrdOucPgrwUtils::csNum(), XrdCl::DefaultRequestTimeout, XrdCl::errDataError, XrdCl::errInvalidArgs, XrdCl::errOperationExpired, XrdCl::FileMsg, XrdCl::AnyObject::Get(), XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), XrdCl::DefaultEnv::GetLog(), XrdCl::ResponseHandler::HandleResponse(), XrdCl::Log::Info(), XrdCl::Status::IsOK(), XrdCl::RetryInfo::NeedRetry(), XrdSys::PageSize, PgWriteImpl(), PgWriteRetry(), XrdCl::RetryInfo::Size(), XrdCl::stError, XrdCl::Log::Warning(), and XrdCl::ResponseHandler::Wrap().

Referenced by XrdCl::File::PgWrite().

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

◆ PgWriteImpl()

XRootDStatus XrdCl::FileStateHandler::PgWriteImpl ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
const void *  buffer,
std::vector< uint32_t > &  cksums,
kXR_char  flags,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write number of pages at a given offset - async

Parameters
offsetoffset from the beginning of the file
sizebuffer size
buffera pointer to a buffer holding data pages
cksumsthe crc32c checksums for each 4KB page
flagsPgWrite flags
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1462 of file XrdClFileStateHandler.cc.

1470  {
1471  XrdSysMutexHelper scopedLock( self->pMutex );
1472 
1473  if( self->pFileState == Error ) return self->pStatus;
1474 
1475  if( self->pFileState != Opened && self->pFileState != Recovering )
1476  return XRootDStatus( stError, errInvalidOp );
1477 
1478  Log *log = DefaultEnv::GetLog();
1479  log->Debug( FileMsg, "[0x%x@%s] Sending a pgwrite command for handle 0x%x to "
1480  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1481  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1482 
1483  //--------------------------------------------------------------------------
1484  // Create the message
1485  //--------------------------------------------------------------------------
1486  Message *msg;
1487  ClientPgWriteRequest *req;
1488  MessageUtils::CreateRequest( msg, req );
1489 
1490  req->requestid = kXR_pgwrite;
1491  req->offset = offset;
1492  req->dlen = size + cksums.size() * sizeof( uint32_t );
1493  req->reqflags = flags;
1494  memcpy( req->fhandle, self->pFileHandle, 4 );
1495 
1496  ChunkList *list = new ChunkList();
1497  list->push_back( ChunkInfo( offset, size, (char*)buffer ) );
1498 
1499  MessageSendParams params;
1500  params.timeout = timeout;
1501  params.followRedirects = false;
1502  params.stateful = true;
1503  params.chunkList = list;
1504  params.crc32cDigests.swap( cksums );
1505 
1507 
1509  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1510 
1511  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1512  }
kXR_char fhandle[4]
Definition: XProtocol.hh:531
std::vector< uint32_t > crc32cDigests

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageSendParams::crc32cDigests, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientPgWriteRequest::dlen, XrdCl::errInvalidOp, Error, ClientPgWriteRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_pgwrite, ClientPgWriteRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientPgWriteRequest::reqflags, ClientPgWriteRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by PgWrite(), and PgWriteRetry().

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

◆ PgWriteRetry()

XRootDStatus XrdCl::FileStateHandler::PgWriteRetry ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
const void *  buffer,
uint32_t  digest,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write number of pages at a given offset - async

Parameters
offsetoffset from the beginning of the file
sizebuffer size
buffera pointer to a buffer holding data pages
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1447 of file XrdClFileStateHandler.cc.

1454  {
1455  std::vector<uint32_t> cksums{ digest };
1456  return PgWriteImpl( self, offset, size, buffer, cksums, PgReadFlags::Retry, handler, timeout );
1457  }

References PgWriteImpl(), and XrdCl::PgReadFlags::Retry.

Referenced by PgWrite().

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

◆ Read()

XRootDStatus XrdCl::FileStateHandler::Read ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Read a data chunk at a given offset - sync

Parameters
offsetoffset from the beginning of the file
sizenumber of bytes to be read
buffera pointer to a buffer big enough to hold the data or 0 if the buffer should be allocated by the system
handlerhandler to be notified when the response arrives, the response parameter will hold a buffer object if the procedure was successful, if a preallocated buffer was specified then the buffer object will "wrap" this buffer
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1008 of file XrdClFileStateHandler.cc.

1014  {
1015  XrdSysMutexHelper scopedLock( self->pMutex );
1016 
1017  if( self->pFileState == Error ) return self->pStatus;
1018 
1019  if( self->pFileState != Opened && self->pFileState != Recovering )
1020  return XRootDStatus( stError, errInvalidOp );
1021 
1022  Log *log = DefaultEnv::GetLog();
1023  log->Debug( FileMsg, "[0x%x@%s] Sending a read command for handle 0x%x to "
1024  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1025  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1026 
1027  Message *msg;
1028  ClientReadRequest *req;
1029  MessageUtils::CreateRequest( msg, req );
1030 
1031  req->requestid = kXR_read;
1032  req->offset = offset;
1033  req->rlen = size;
1034  memcpy( req->fhandle, self->pFileHandle, 4 );
1035 
1036  ChunkList *list = new ChunkList();
1037  list->push_back( ChunkInfo( offset, size, buffer ) );
1038 
1040  MessageSendParams params;
1041  params.timeout = timeout;
1042  params.followRedirects = false;
1043  params.stateful = true;
1044  params.chunkList = list;
1046  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1047 
1048  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1049  }
kXR_int64 offset
Definition: XProtocol.hh:646
kXR_unt16 requestid
Definition: XProtocol.hh:644
kXR_char fhandle[4]
Definition: XProtocol.hh:645

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientReadRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_read, ClientReadRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientReadRequest::requestid, ClientReadRequest::rlen, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by PgRead(), and XrdCl::File::Read().

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

◆ ReadV()

XRootDStatus XrdCl::FileStateHandler::ReadV ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
struct iovec *  iov,
int  iovcnt,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Read data into scattered buffers in one operation - async

Parameters
offsetoffset from the beginning of the file
iovlist of the buffers to be written
iovcntnumber of buffers
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 then the environment default will be used
Returns
status of the operation

Definition at line 1805 of file XrdClFileStateHandler.cc.

1811  {
1812  XrdSysMutexHelper scopedLock( self->pMutex );
1813 
1814  if( self->pFileState == Error ) return self->pStatus;
1815 
1816  if( self->pFileState != Opened && self->pFileState != Recovering )
1817  return XRootDStatus( stError, errInvalidOp );
1818 
1819  Log *log = DefaultEnv::GetLog();
1820  log->Debug( FileMsg, "[0x%x@%s] Sending a read command for handle 0x%x to "
1821  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1822  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1823 
1824  Message *msg;
1825  ClientReadRequest *req;
1826  MessageUtils::CreateRequest( msg, req );
1827 
1828  // calculate the total read size
1829  size_t size = std::accumulate( iov, iov + iovcnt, 0, []( size_t acc, iovec &rhs )
1830  {
1831  return acc + rhs.iov_len;
1832  } );
1833  req->requestid = kXR_read;
1834  req->offset = offset;
1835  req->rlen = size;
1836  msg->SetVirtReqID( kXR_virtReadv );
1837  memcpy( req->fhandle, self->pFileHandle, 4 );
1838 
1839  ChunkList *list = new ChunkList();
1840  list->reserve( iovcnt );
1841  uint64_t choff = offset;
1842  for( int i = 0; i < iovcnt; ++i )
1843  {
1844  list->emplace_back( choff, iov[i].iov_len, iov[i].iov_base );
1845  choff += iov[i].iov_len;
1846  }
1847 
1849  MessageSendParams params;
1850  params.timeout = timeout;
1851  params.followRedirects = false;
1852  params.stateful = true;
1853  params.chunkList = list;
1855  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1856 
1857  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1858  }
@ kXR_virtReadv
Definition: XProtocol.hh:150
void SetVirtReqID(uint16_t virtReqID)
Set virtual request ID for the message.

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientReadRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_read, kXR_virtReadv, ClientReadRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientReadRequest::requestid, ClientReadRequest::rlen, XrdCl::XRootDTransport::SetDescription(), XrdCl::Message::SetVirtReqID(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::ReadV().

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

◆ SetProperty()

bool XrdCl::FileStateHandler::SetProperty ( const std::string &  name,
const std::string &  value 
)

Set file property

See also
File::GetProperty for propert list

Definition at line 2242 of file XrdClFileStateHandler.cc.

2244  {
2245  XrdSysMutexHelper scopedLock( pMutex );
2246  if( name == "ReadRecovery" )
2247  {
2248  if( value == "true" ) pDoRecoverRead = true;
2249  else pDoRecoverRead = false;
2250  return true;
2251  }
2252  else if( name == "WriteRecovery" )
2253  {
2254  if( value == "true" ) pDoRecoverWrite = true;
2255  else pDoRecoverWrite = false;
2256  return true;
2257  }
2258  else if( name == "FollowRedirects" )
2259  {
2260  if( value == "true" ) pFollowRedirects = true;
2261  else pFollowRedirects = false;
2262  return true;
2263  }
2264  else if( name == "BundledClose" )
2265  {
2266  if( value == "true" ) pAllowBundledClose = true;
2267  else pAllowBundledClose = false;
2268  return true;
2269  }
2270  return false;
2271  }

◆ SetXAttr()

XRootDStatus XrdCl::FileStateHandler::SetXAttr ( std::shared_ptr< FileStateHandler > &  self,
const std::vector< xattr_t > &  attrs,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Set extended attributes - async

Parameters
attrs: list of extended attributes to set
handler: handler to be notified when the response arrives, the response parameter will hold a std::vector of XAttrStatus objects
timeout: timeout value, if 0 the environment default will be used
Returns
: status of the operation

Definition at line 1945 of file XrdClFileStateHandler.cc.

1949  {
1950  XrdSysMutexHelper scopedLock( self->pMutex );
1951 
1952  if( self->pFileState == Error ) return self->pStatus;
1953 
1954  if( self->pFileState != Opened && self->pFileState != Recovering )
1955  return XRootDStatus( stError, errInvalidOp );
1956 
1957  Log *log = DefaultEnv::GetLog();
1958  log->Debug( FileMsg, "[0x%x@%s] Sending a fattr set command for handle 0x%x to "
1959  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1960  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1961 
1962  //--------------------------------------------------------------------------
1963  // Issue a new fattr get request
1964  //--------------------------------------------------------------------------
1965  return XAttrOperationImpl( self, kXR_fattrSet, 0, attrs, handler, timeout );
1966  }
@ kXR_fattrSet
Definition: XProtocol.hh:273

References XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), kXR_fattrSet, Opened, Recovering, and XrdCl::stError.

Referenced by XrdCl::File::SetXAttr().

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

◆ Stat()

XRootDStatus XrdCl::FileStateHandler::Stat ( std::shared_ptr< FileStateHandler > &  self,
bool  force,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Obtain status information for this file - async

Parameters
forcedo not use the cached information, force re-stating
handlerhandler to be notified when the response arrives, the response parameter will hold a StatInfo object if the procedure is successful
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 951 of file XrdClFileStateHandler.cc.

955  {
956  XrdSysMutexHelper scopedLock( self->pMutex );
957 
958  if( self->pFileState == Error ) return self->pStatus;
959 
960  if( self->pFileState != Opened && self->pFileState != Recovering )
961  return XRootDStatus( stError, errInvalidOp );
962 
963  //--------------------------------------------------------------------------
964  // Return the cached info
965  //--------------------------------------------------------------------------
966  if( !force )
967  {
968  AnyObject *obj = new AnyObject();
969  obj->Set( new StatInfo( *self->pStatInfo ) );
970  if (handler)
971  handler->HandleResponseWithHosts( new XRootDStatus(), obj, new HostList() );
972  return XRootDStatus();
973  }
974 
975  Log *log = DefaultEnv::GetLog();
976  log->Debug( FileMsg, "[0x%x@%s] Sending a stat command for handle 0x%x to "
977  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
978  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
979 
980  //--------------------------------------------------------------------------
981  // Issue a new stat request
982  // stating a file handle doesn't work (fixed in 3.2.0) so we need to
983  // stat the pat
984  //--------------------------------------------------------------------------
985  Message *msg;
986  ClientStatRequest *req;
987  std::string path = self->pFileUrl->GetPath();
988  MessageUtils::CreateRequest( msg, req );
989 
990  req->requestid = kXR_stat;
991  memcpy( req->fhandle, self->pFileHandle, 4 );
992 
993  MessageSendParams params;
994  params.timeout = timeout;
995  params.followRedirects = false;
996  params.stateful = true;
998 
1000  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1001 
1002  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1003  }
kXR_char fhandle[4]
Definition: XProtocol.hh:769
kXR_unt16 requestid
Definition: XProtocol.hh:766
void Set(Type object, bool own=true)
virtual void HandleResponseWithHosts(XRootDStatus *status, AnyObject *response, HostList *hostList)
std::vector< HostInfo > HostList

References XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientStatRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), XrdCl::ResponseHandler::HandleResponseWithHosts(), kXR_stat, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientStatRequest::requestid, XrdCl::AnyObject::Set(), XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Stat().

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

◆ Sync()

XRootDStatus XrdCl::FileStateHandler::Sync ( std::shared_ptr< FileStateHandler > &  self,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Commit all pending disk writes - async

Parameters
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1517 of file XrdClFileStateHandler.cc.

1520  {
1521  XrdSysMutexHelper scopedLock( self->pMutex );
1522 
1523  if( self->pFileState == Error ) return self->pStatus;
1524 
1525  if( self->pFileState != Opened && self->pFileState != Recovering )
1526  return XRootDStatus( stError, errInvalidOp );
1527 
1528  Log *log = DefaultEnv::GetLog();
1529  log->Debug( FileMsg, "[0x%x@%s] Sending a sync command for handle 0x%x to "
1530  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1531  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1532 
1533  Message *msg;
1534  ClientSyncRequest *req;
1535  MessageUtils::CreateRequest( msg, req );
1536 
1537  req->requestid = kXR_sync;
1538  memcpy( req->fhandle, self->pFileHandle, 4 );
1539 
1540  MessageSendParams params;
1541  params.timeout = timeout;
1542  params.followRedirects = false;
1543  params.stateful = true;
1545 
1547  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1548 
1549  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1550  }
kXR_char fhandle[4]
Definition: XProtocol.hh:780
@ kXR_sync
Definition: XProtocol.hh:128
kXR_unt16 requestid
Definition: XProtocol.hh:779

References XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientSyncRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_sync, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientSyncRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Sync().

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

◆ Tick()

void XrdCl::FileStateHandler::Tick ( time_t  now)

Tick.

Definition at line 2705 of file XrdClFileStateHandler.cc.

2706  {
2707  if (pMutex.CondLock())
2708  {TimeOutRequests( now );
2709  pMutex.UnLock();
2710  }
2711  }
void TimeOutRequests(time_t now)
Declare timeout on requests being recovered.

References XrdSysMutex::CondLock(), TimeOutRequests(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ TimeOutRequests()

void XrdCl::FileStateHandler::TimeOutRequests ( time_t  now)

Declare timeout on requests being recovered.

Definition at line 2716 of file XrdClFileStateHandler.cc.

2717  {
2718  if( !pToBeRecovered.empty() )
2719  {
2720  Log *log = DefaultEnv::GetLog();
2721  log->Dump( FileMsg, "[0x%x@%s] Got a timer event", this,
2722  pFileUrl->GetURL().c_str() );
2723  RequestList::iterator it;
2725  for( it = pToBeRecovered.begin(); it != pToBeRecovered.end(); )
2726  {
2727  if( it->params.expires <= now )
2728  {
2729  jobMan->QueueJob( new ResponseJob(
2730  it->handler,
2732  0, it->params.hostList ) );
2733  it = pToBeRecovered.erase( it );
2734  }
2735  else
2736  ++it;
2737  }
2738  }
2739  }
A synchronized queue.

References XrdCl::Log::Dump(), XrdCl::errOperationExpired, XrdCl::FileMsg, XrdCl::PostMaster::GetJobManager(), XrdCl::DefaultEnv::GetLog(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::URL::GetURL(), XrdCl::JobManager::QueueJob(), and XrdCl::stError.

Referenced by Tick().

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

◆ Truncate()

XRootDStatus XrdCl::FileStateHandler::Truncate ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  size,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Truncate the file to a particular size - async

Parameters
sizedesired size of the file
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1555 of file XrdClFileStateHandler.cc.

1559  {
1560  XrdSysMutexHelper scopedLock( self->pMutex );
1561 
1562  if( self->pFileState == Error ) return self->pStatus;
1563 
1564  if( self->pFileState != Opened && self->pFileState != Recovering )
1565  return XRootDStatus( stError, errInvalidOp );
1566 
1567  Log *log = DefaultEnv::GetLog();
1568  log->Debug( FileMsg, "[0x%x@%s] Sending a truncate command for handle 0x%x to "
1569  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1570  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1571 
1572  Message *msg;
1573  ClientTruncateRequest *req;
1574  MessageUtils::CreateRequest( msg, req );
1575 
1576  req->requestid = kXR_truncate;
1577  memcpy( req->fhandle, self->pFileHandle, 4 );
1578  req->offset = size;
1579 
1580  MessageSendParams params;
1581  params.timeout = timeout;
1582  params.followRedirects = false;
1583  params.stateful = true;
1585 
1587  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1588 
1589  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1590  }
@ kXR_truncate
Definition: XProtocol.hh:140
kXR_char fhandle[4]
Definition: XProtocol.hh:792

References XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientTruncateRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_truncate, ClientTruncateRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientTruncateRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Truncate().

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

◆ TryOtherServer()

XRootDStatus XrdCl::FileStateHandler::TryOtherServer ( std::shared_ptr< FileStateHandler > &  self,
uint16_t  timeout 
)
static

Try other data server.

Definition at line 2767 of file XrdClFileStateHandler.cc.

2768  {
2769  XrdSysMutexHelper scopedLock( self->pMutex );
2770 
2771  if( self->pFileState != Opened || !self->pLoadBalancer )
2772  return XRootDStatus( stError, errInvalidOp );
2773 
2774  self->pFileState = Recovering;
2775 
2776  Log *log = DefaultEnv::GetLog();
2777  log->Debug( FileMsg, "[0x%x@%s] Reopen file at next data server.",
2778  self.get(), self->pFileUrl->GetURL().c_str() );
2779 
2780  // merge CGI
2781  auto lbcgi = self->pLoadBalancer->GetParams();
2782  auto dtcgi = self->pDataServer->GetParams();
2783  MessageUtils::MergeCGI( lbcgi, dtcgi, false );
2784  // update tried CGI
2785  auto itr = lbcgi.find( "tried" );
2786  if( itr == lbcgi.end() )
2787  lbcgi["tried"] = self->pDataServer->GetHostName();
2788  else
2789  {
2790  std::string tried = itr->second;
2791  tried += "," + self->pDataServer->GetHostName();
2792  lbcgi["tried"] = tried;
2793  }
2794  self->pLoadBalancer->SetParams( lbcgi );
2795 
2796  return ReOpenFileAtServer( self, *self->pLoadBalancer, timeout );
2797  }

References XrdCl::Log::Debug(), XrdCl::errInvalidOp, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), XrdCl::MessageUtils::MergeCGI(), Opened, Recovering, and XrdCl::stError.

Referenced by XrdCl::File::TryOtherServer().

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

◆ UnLock()

void XrdCl::FileStateHandler::UnLock ( )
inline

Unlock the internal lock.

Definition at line 688 of file XrdClFileStateHandler.hh.

689  {
690  pMutex.UnLock();
691  }

◆ VectorRead()

XRootDStatus XrdCl::FileStateHandler::VectorRead ( std::shared_ptr< FileStateHandler > &  self,
const ChunkList chunks,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Read scattered data chunks in one operation - async

Parameters
chunkslist of the chunks to be read
buffera pointer to a buffer big enough to hold the data
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 then the environment default will be used
Returns
status of the operation

Definition at line 1595 of file XrdClFileStateHandler.cc.

1600  {
1601  //--------------------------------------------------------------------------
1602  // Sanity check
1603  //--------------------------------------------------------------------------
1604  XrdSysMutexHelper scopedLock( self->pMutex );
1605 
1606  if( self->pFileState == Error ) return self->pStatus;
1607 
1608  if( self->pFileState != Opened && self->pFileState != Recovering )
1609  return XRootDStatus( stError, errInvalidOp );
1610 
1611  Log *log = DefaultEnv::GetLog();
1612  log->Debug( FileMsg, "[0x%x@%s] Sending a vector read command for handle "
1613  "0x%x to %s", self.get(), self->pFileUrl->GetURL().c_str(),
1614  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1615 
1616  //--------------------------------------------------------------------------
1617  // Build the message
1618  //--------------------------------------------------------------------------
1619  Message *msg;
1620  ClientReadVRequest *req;
1621  MessageUtils::CreateRequest( msg, req, sizeof(readahead_list)*chunks.size() );
1622 
1623  req->requestid = kXR_readv;
1624  req->dlen = sizeof(readahead_list)*chunks.size();
1625 
1626  ChunkList *list = new ChunkList();
1627  char *cursor = (char*)buffer;
1628 
1629  //--------------------------------------------------------------------------
1630  // Copy the chunk info
1631  //--------------------------------------------------------------------------
1632  readahead_list *dataChunk = (readahead_list*)msg->GetBuffer( 24 );
1633  for( size_t i = 0; i < chunks.size(); ++i )
1634  {
1635  dataChunk[i].rlen = chunks[i].length;
1636  dataChunk[i].offset = chunks[i].offset;
1637  memcpy( dataChunk[i].fhandle, self->pFileHandle, 4 );
1638 
1639  void *chunkBuffer;
1640  if( cursor )
1641  {
1642  chunkBuffer = cursor;
1643  cursor += chunks[i].length;
1644  }
1645  else
1646  chunkBuffer = chunks[i].buffer;
1647 
1648  list->push_back( ChunkInfo( chunks[i].offset,
1649  chunks[i].length,
1650  chunkBuffer ) );
1651  }
1652 
1653  //--------------------------------------------------------------------------
1654  // Send the message
1655  //--------------------------------------------------------------------------
1656  MessageSendParams params;
1657  params.timeout = timeout;
1658  params.followRedirects = false;
1659  params.stateful = true;
1660  params.chunkList = list;
1662 
1664  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1665 
1666  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1667  }
kXR_int32 rlen
Definition: XProtocol.hh:660
kXR_int64 offset
Definition: XProtocol.hh:661
kXR_unt16 requestid
Definition: XProtocol.hh:670

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientReadVRequest::dlen, XrdCl::errInvalidOp, Error, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetLog(), kXR_readv, readahead_list::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientReadVRequest::requestid, readahead_list::rlen, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::VectorRead().

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

◆ VectorWrite()

XRootDStatus XrdCl::FileStateHandler::VectorWrite ( std::shared_ptr< FileStateHandler > &  self,
const ChunkList chunks,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write scattered data chunks in one operation - async

Parameters
chunkslist of the chunks to be read
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 then the environment default will be used
Returns
status of the operation

Definition at line 1672 of file XrdClFileStateHandler.cc.

1676  {
1677  //--------------------------------------------------------------------------
1678  // Sanity check
1679  //--------------------------------------------------------------------------
1680  XrdSysMutexHelper scopedLock( self->pMutex );
1681 
1682  if( self->pFileState == Error ) return self->pStatus;
1683 
1684  if( self->pFileState != Opened && self->pFileState != Recovering )
1685  return XRootDStatus( stError, errInvalidOp );
1686 
1687  Log *log = DefaultEnv::GetLog();
1688  log->Debug( FileMsg, "[0x%x@%s] Sending a vector write command for handle "
1689  "0x%x to %s", self.get(), self->pFileUrl->GetURL().c_str(),
1690  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1691 
1692  //--------------------------------------------------------------------------
1693  // Determine the size of the payload
1694  //--------------------------------------------------------------------------
1695 
1696  // the size of write vector
1697  uint32_t payloadSize = sizeof(XrdProto::write_list) * chunks.size();
1698 
1699  //--------------------------------------------------------------------------
1700  // Build the message
1701  //--------------------------------------------------------------------------
1702  Message *msg;
1703  ClientWriteVRequest *req;
1704  MessageUtils::CreateRequest( msg, req, payloadSize );
1705 
1706  req->requestid = kXR_writev;
1707  req->dlen = sizeof(XrdProto::write_list) * chunks.size();
1708 
1709  ChunkList *list = new ChunkList();
1710 
1711  //--------------------------------------------------------------------------
1712  // Copy the chunk info
1713  //--------------------------------------------------------------------------
1714  XrdProto::write_list *writeList =
1715  reinterpret_cast<XrdProto::write_list*>( msg->GetBuffer( 24 ) );
1716 
1717 
1718 
1719  for( size_t i = 0; i < chunks.size(); ++i )
1720  {
1721  writeList[i].wlen = chunks[i].length;
1722  writeList[i].offset = chunks[i].offset;
1723  memcpy( writeList[i].fhandle, self->pFileHandle, 4 );
1724 
1725  list->push_back( ChunkInfo( chunks[i].offset,
1726  chunks[i].length,
1727  chunks[i].buffer ) );
1728  }
1729 
1730  //--------------------------------------------------------------------------
1731  // Send the message
1732  //--------------------------------------------------------------------------
1733  MessageSendParams params;
1734  params.timeout = timeout;
1735  params.followRedirects = false;
1736  params.stateful = true;
1737  params.chunkList = list;
1739 
1741  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1742 
1743  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1744  }
kXR_unt16 requestid
Definition: XProtocol.hh:818

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientWriteVRequest::dlen, XrdCl::errInvalidOp, Error, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::Buffer::GetBuffer(), XrdCl::DefaultEnv::GetLog(), kXR_writev, XrdProto::write_list::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientWriteVRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, XrdCl::MessageSendParams::timeout, and XrdProto::write_list::wlen.

Referenced by XrdCl::File::VectorWrite().

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

◆ Visa()

XRootDStatus XrdCl::FileStateHandler::Visa ( std::shared_ptr< FileStateHandler > &  self,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Get access token to a file - async

Parameters
handlerhandler to be notified when the response arrives, the response parameter will hold a Buffer object if the procedure is successful
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1906 of file XrdClFileStateHandler.cc.

1909  {
1910  XrdSysMutexHelper scopedLock( self->pMutex );
1911 
1912  if( self->pFileState == Error ) return self->pStatus;
1913 
1914  if( self->pFileState != Opened && self->pFileState != Recovering )
1915  return XRootDStatus( stError, errInvalidOp );
1916 
1917  Log *log = DefaultEnv::GetLog();
1918  log->Debug( FileMsg, "[0x%x@%s] Sending a visa command for handle 0x%x to "
1919  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1920  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1921 
1922  Message *msg;
1923  ClientQueryRequest *req;
1924  MessageUtils::CreateRequest( msg, req );
1925 
1926  req->requestid = kXR_query;
1927  req->infotype = kXR_Qvisa;
1928  memcpy( req->fhandle, self->pFileHandle, 4 );
1929 
1930  MessageSendParams params;
1931  params.timeout = timeout;
1932  params.followRedirects = false;
1933  params.stateful = true;
1935 
1937  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1938 
1939  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1940  }
@ kXR_Qvisa
Definition: XProtocol.hh:622

References XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), XrdCl::errInvalidOp, Error, ClientQueryRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), ClientQueryRequest::infotype, kXR_query, kXR_Qvisa, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientQueryRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Visa().

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

◆ Write() [1/3]

XRootDStatus XrdCl::FileStateHandler::Write ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
Buffer &&  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write a data chunk at a given offset - async

Parameters
offsetoffset from the beginning of the file
bufferr-value reference to Buffer object, in this case XrdCl runtime takes ownership of the buffer
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1215 of file XrdClFileStateHandler.cc.

1220  {
1221  //--------------------------------------------------------------------------
1222  // If the memory is not page (4KB) aligned we cannot use the kernel buffer
1223  // so fall back to normal write
1224  //--------------------------------------------------------------------------
1225  if( !XrdSys::KernelBuffer::IsPageAligned( buffer.GetBuffer() ) || self->pIsChannelEncrypted )
1226  {
1227  Log *log = DefaultEnv::GetLog();
1228  log->Info( FileMsg, "[0x%x@%s] Buffer is not page aligned (4KB), cannot "
1229  "convert it to kernel space buffer.", self.get(), self->pFileUrl->GetURL().c_str(),
1230  *((uint32_t*)self->pFileHandle) );
1231 
1232  void *buff = buffer.GetBuffer();
1233  uint32_t size = buffer.GetSize();
1234  ReleaseBufferHandler *wrtHandler =
1235  new ReleaseBufferHandler( std::move( buffer ), handler );
1236  XRootDStatus st = self->Write( self, offset, size, buff, wrtHandler, timeout );
1237  if( !st.IsOK() )
1238  {
1239  buffer = std::move( wrtHandler->GetBuffer() );
1240  delete wrtHandler;
1241  }
1242  return st;
1243  }
1244 
1245  //--------------------------------------------------------------------------
1246  // Transfer the data from user space to kernel space
1247  //--------------------------------------------------------------------------
1248  uint32_t length = buffer.GetSize();
1249  char *ubuff = buffer.Release();
1250 
1251  std::unique_ptr<XrdSys::KernelBuffer> kbuff( new XrdSys::KernelBuffer() );
1252  ssize_t ret = XrdSys::Move( ubuff, *kbuff, length );
1253  if( ret < 0 )
1254  return XRootDStatus( stError, errInternal, XProtocol::mapError( errno ) );
1255 
1256  //--------------------------------------------------------------------------
1257  // Now create a write request and enqueue it
1258  //--------------------------------------------------------------------------
1259  return WriteKernelBuffer( self, offset, ret, std::move( kbuff ), handler, timeout );
1260  }
static int mapError(int rc)
Definition: XProtocol.hh:1358
char * Release()
Release the buffer.
Definition: XrdClBuffer.hh:238
static bool IsPageAligned(const void *ptr)
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:56
ssize_t Move(KernelBuffer &kbuff, char *&ubuff)

References XrdCl::errInternal, XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), XrdCl::Log::Info(), XrdCl::Status::IsOK(), XrdSys::KernelBuffer::IsPageAligned(), XProtocol::mapError(), XrdSys::Move(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ Write() [2/3]

XRootDStatus XrdCl::FileStateHandler::Write ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
const void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write a data chunk at a given offset - async

Parameters
offsetoffset from the beginning of the file
sizenumber of bytes to be written
buffera pointer to the buffer holding the data to be written
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1167 of file XrdClFileStateHandler.cc.

1173  {
1174  XrdSysMutexHelper scopedLock( self->pMutex );
1175 
1176  if( self->pFileState == Error ) return self->pStatus;
1177 
1178  if( self->pFileState != Opened && self->pFileState != Recovering )
1179  return XRootDStatus( stError, errInvalidOp );
1180 
1181  Log *log = DefaultEnv::GetLog();
1182  log->Debug( FileMsg, "[0x%x@%s] Sending a write command for handle 0x%x to "
1183  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1184  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1185 
1186  Message *msg;
1187  ClientWriteRequest *req;
1188  MessageUtils::CreateRequest( msg, req );
1189 
1190  req->requestid = kXR_write;
1191  req->offset = offset;
1192  req->dlen = size;
1193  memcpy( req->fhandle, self->pFileHandle, 4 );
1194 
1195  ChunkList *list = new ChunkList();
1196  list->push_back( ChunkInfo( 0, size, (char*)buffer ) );
1197 
1198  MessageSendParams params;
1199  params.timeout = timeout;
1200  params.followRedirects = false;
1201  params.stateful = true;
1202  params.chunkList = list;
1203 
1205 
1207  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1208 
1209  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1210  }

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientWriteRequest::dlen, XrdCl::errInvalidOp, Error, ClientWriteRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_write, ClientWriteRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientWriteRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::Write().

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

◆ Write() [3/3]

XRootDStatus XrdCl::FileStateHandler::Write ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
uint32_t  size,
Optional< uint64_t >  fdoff,
int  fd,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write a data from a given file descriptor at a given offset - async

Parameters
offsetoffset from the beginning of the file
sizenumber of bytes to be written
fdoffoffset of the data to be written from the file descriptor (optional, if not provided will copy data from the file descriptor at the current cursor position)
fdfile descriptor open for reading
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 the environment default will be used
Returns
status of the operation

Definition at line 1265 of file XrdClFileStateHandler.cc.

1272  {
1273  //--------------------------------------------------------------------------
1274  // Read the data from the file descriptor into a kernel buffer
1275  //--------------------------------------------------------------------------
1276  std::unique_ptr<XrdSys::KernelBuffer> kbuff( new XrdSys::KernelBuffer() );
1277  ssize_t ret = fdoff ? XrdSys::Read( fd, *kbuff, size, *fdoff ) :
1278  XrdSys::Read( fd, *kbuff, size );
1279  if( ret < 0 )
1280  return XRootDStatus( stError, errInternal, XProtocol::mapError( errno ) );
1281 
1282  //--------------------------------------------------------------------------
1283  // Now create a write request and enqueue it
1284  //--------------------------------------------------------------------------
1285  return WriteKernelBuffer( self, offset, ret, std::move( kbuff ), handler, timeout );
1286  }
ssize_t Read(int fd, KernelBuffer &buffer, uint32_t length, int64_t offset)

References XrdCl::errInternal, XProtocol::mapError(), XrdSys::Read(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ WriteV()

XRootDStatus XrdCl::FileStateHandler::WriteV ( std::shared_ptr< FileStateHandler > &  self,
uint64_t  offset,
const struct iovec *  iov,
int  iovcnt,
ResponseHandler handler,
uint16_t  timeout = 0 
)
static

Write scattered buffers in one operation - async

Parameters
offsetoffset from the beginning of the file
iovlist of the buffers to be written
iovcntnumber of buffers
handlerhandler to be notified when the response arrives
timeouttimeout value, if 0 then the environment default will be used
Returns
status of the operation

Definition at line 1749 of file XrdClFileStateHandler.cc.

1755  {
1756  XrdSysMutexHelper scopedLock( self->pMutex );
1757 
1758  if( self->pFileState == Error ) return self->pStatus;
1759 
1760  if( self->pFileState != Opened && self->pFileState != Recovering )
1761  return XRootDStatus( stError, errInvalidOp );
1762 
1763  Log *log = DefaultEnv::GetLog();
1764  log->Debug( FileMsg, "[0x%x@%s] Sending a write command for handle 0x%x to "
1765  "%s", self.get(), self->pFileUrl->GetURL().c_str(),
1766  *((uint32_t*)self->pFileHandle), self->pDataServer->GetHostId().c_str() );
1767 
1768  Message *msg;
1769  ClientWriteRequest *req;
1770  MessageUtils::CreateRequest( msg, req );
1771 
1772  ChunkList *list = new ChunkList();
1773 
1774  uint32_t size = 0;
1775  for( int i = 0; i < iovcnt; ++i )
1776  {
1777  if( iov[i].iov_len == 0 ) continue;
1778  size += iov[i].iov_len;
1779  list->push_back( ChunkInfo( 0, iov[i].iov_len,
1780  (char*)iov[i].iov_base ) );
1781  }
1782 
1783  req->requestid = kXR_write;
1784  req->offset = offset;
1785  req->dlen = size;
1786  memcpy( req->fhandle, self->pFileHandle, 4 );
1787 
1788  MessageSendParams params;
1789  params.timeout = timeout;
1790  params.followRedirects = false;
1791  params.stateful = true;
1792  params.chunkList = list;
1793 
1795 
1797  StatefulHandler *stHandler = new StatefulHandler( self, handler, msg, params );
1798 
1799  return SendOrQueue( self, *self->pDataServer, msg, stHandler, params );
1800  }

References XrdCl::MessageSendParams::chunkList, XrdCl::MessageUtils::CreateRequest(), XrdCl::Log::Debug(), ClientWriteRequest::dlen, XrdCl::errInvalidOp, Error, ClientWriteRequest::fhandle, XrdCl::FileMsg, XrdCl::MessageSendParams::followRedirects, XrdCl::DefaultEnv::GetLog(), kXR_write, ClientWriteRequest::offset, Opened, XrdCl::MessageUtils::ProcessSendParams(), Recovering, ClientWriteRequest::requestid, XrdCl::XRootDTransport::SetDescription(), XrdCl::MessageSendParams::stateful, XrdCl::stError, and XrdCl::MessageSendParams::timeout.

Referenced by XrdCl::File::WriteV().

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

Friends And Related Function Documentation

◆ ::OpenHandler

friend class ::OpenHandler
friend

Definition at line 84 of file XrdClFileStateHandler.hh.

◆ ::PgReadHandler

friend class ::PgReadHandler
friend

Definition at line 81 of file XrdClFileStateHandler.hh.

◆ ::PgReadRetryHandler

friend class ::PgReadRetryHandler
friend

Definition at line 82 of file XrdClFileStateHandler.hh.

◆ ::PgReadSubstitutionHandler

friend class ::PgReadSubstitutionHandler
friend

Definition at line 83 of file XrdClFileStateHandler.hh.


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