XRootD
XrdCl::LocalFileHandler Class Reference

#include <XrdClLocalFileHandler.hh>

+ Collaboration diagram for XrdCl::LocalFileHandler:

Public Member Functions

 LocalFileHandler ()
 
 ~LocalFileHandler ()
 
XRootDStatus Close (ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus DelXAttr (const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus ExecRequest (const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
 Translate an XRootD request into LocalFileHandler call. More...
 
XRootDStatus Fcntl (const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0)
 
const HostListGetHostList ()
 
XRootDStatus GetXAttr (const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus ListXAttr (ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Open (const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Open (const URL *url, const Message *req, AnyObject *&resp)
 Handle local redirect to given URL triggered by the given request. More...
 
XRootDStatus QueueTask (XRootDStatus *st, AnyObject *obj, ResponseHandler *handler)
 
XRootDStatus Read (uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus ReadV (uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
 
void SetHostList (const HostList &hostList)
 
XRootDStatus SetXAttr (const std::vector< xattr_t > &attrs, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Stat (ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Sync (ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Truncate (uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus VectorRead (const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus VectorWrite (const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Visa (ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Write (uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus WriteV (uint64_t offset, ChunkList *chunks, ResponseHandler *handler, uint16_t timeout=0)
 

Static Public Member Functions

static XRootDStatus MkdirPath (const std::string &path)
 

Detailed Description

Definition at line 32 of file XrdClLocalFileHandler.hh.

Constructor & Destructor Documentation

◆ LocalFileHandler()

XrdCl::LocalFileHandler::LocalFileHandler ( )

Definition at line 226 of file XrdClLocalFileHandler.cc.

226  :
227  fd( -1 )
228  {
229  }

◆ ~LocalFileHandler()

XrdCl::LocalFileHandler::~LocalFileHandler ( )

Definition at line 234 of file XrdClLocalFileHandler.cc.

235  {
236 
237  }

Member Function Documentation

◆ Close()

XRootDStatus XrdCl::LocalFileHandler::Close ( ResponseHandler handler,
uint16_t  timeout = 0 
)

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 265 of file XrdClLocalFileHandler.cc.

267  {
268  if( close( fd ) == -1 )
269  {
270  Log *log = DefaultEnv::GetLog();
271  log->Error( FileMsg, "Close: file fd: %i %s", fd, XrdSysE2T( errno ) );
272  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
273  return QueueTask( error, 0, handler );
274  }
275 
276  return QueueTask( new XRootDStatus(), 0, handler );
277  }
#define close(a)
Definition: XrdPosix.hh:48
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
static Log * GetLog()
Get default log.
XRootDStatus QueueTask(XRootDStatus *st, AnyObject *obj, ResponseHandler *handler)
Handle diagnostics.
Definition: XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint64_t FileMsg
const uint16_t errLocalError
Definition: XrdClStatus.hh:107

References close, XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), QueueTask(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ DelXAttr()

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

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 692 of file XrdClLocalFileHandler.cc.

695  {
696  XrdSysXAttr *xattr = XrdSysFAttr::Xat;
697  std::vector<XAttrStatus> response;
698 
699  auto itr = attrs.begin();
700  for( ; itr != attrs.end(); ++itr )
701  {
702  std::string name = *itr;
703  int err = xattr->Del( name.c_str(), 0, fd );
704  XRootDStatus status = err < 0 ? XRootDStatus( stError, errLocalError, -err ) :
705  XRootDStatus();
706 
707  response.push_back( XAttrStatus( name, status ) );
708  }
709 
710  AnyObject *resp = new AnyObject();
711  resp->Set( new std::vector<XAttrStatus>( std::move( response ) ) );
712 
713  return QueueTask( new XRootDStatus(), resp, handler );
714  }
void Set(Type object, bool own=true)
static XrdSysXAttr * Xat
Definition: XrdSysFAttr.hh:51
virtual int Del(const char *Aname, const char *Path, int fd=-1)=0
Extended attribute operation status.

References XrdSysXAttr::Del(), XrdCl::errLocalError, QueueTask(), XrdCl::AnyObject::Set(), XrdCl::stError, and XrdSysFAttr::Xat.

+ Here is the call graph for this function:

◆ ExecRequest()

XRootDStatus XrdCl::LocalFileHandler::ExecRequest ( const URL url,
Message msg,
ResponseHandler handler,
MessageSendParams sendParams 
)

Translate an XRootD request into LocalFileHandler call.

Definition at line 998 of file XrdClLocalFileHandler.cc.

1002  {
1003  ClientRequest *req = reinterpret_cast<ClientRequest*>( msg->GetBuffer() );
1004 
1005  switch( req->header.requestid )
1006  {
1007  case kXR_open:
1008  {
1009  XRootDStatus st = Open( url.GetURL(), req->open.options,
1010  req->open.mode, handler, sendParams.timeout );
1011  delete msg; // in case of other operations msg is owned by the handler
1012  return st;
1013  }
1014 
1015  case kXR_close:
1016  {
1017  return Close( handler, sendParams.timeout );
1018  }
1019 
1020  case kXR_stat:
1021  {
1022  return Stat( handler, sendParams.timeout );
1023  }
1024 
1025  case kXR_read:
1026  {
1027  if( msg->GetVirtReqID() == kXR_virtReadv )
1028  {
1029  auto &chunkList = *sendParams.chunkList;
1030  struct iovec iov[chunkList.size()];
1031  for( size_t i = 0; i < chunkList.size() ; ++i )
1032  {
1033  iov[i].iov_base = chunkList[i].buffer;
1034  iov[i].iov_len = chunkList[i].length;
1035  }
1036  return ReadV( chunkList.front().offset, iov, chunkList.size(),
1037  handler, sendParams.timeout );
1038  }
1039 
1040  return Read( req->read.offset, req->read.rlen,
1041  sendParams.chunkList->front().buffer,
1042  handler, sendParams.timeout );
1043  }
1044 
1045  case kXR_write:
1046  {
1047  ChunkList *chunks = sendParams.chunkList;
1048  if( chunks->size() == 1 )
1049  {
1050  // it's an ordinary write
1051  return Write( req->write.offset, req->write.dlen,
1052  chunks->front().buffer, handler,
1053  sendParams.timeout );
1054  }
1055  // it's WriteV call
1056  return WriteV( req->write.offset, sendParams.chunkList,
1057  handler, sendParams.timeout );
1058  }
1059 
1060  case kXR_sync:
1061  {
1062  return Sync( handler, sendParams.timeout );
1063  }
1064 
1065  case kXR_truncate:
1066  {
1067  return Truncate( req->truncate.offset, handler, sendParams.timeout );
1068  }
1069 
1070  case kXR_writev:
1071  {
1072  return VectorWrite( *sendParams.chunkList, handler,
1073  sendParams.timeout );
1074  }
1075 
1076  case kXR_readv:
1077  {
1078  return VectorRead( *sendParams.chunkList, 0,
1079  handler, sendParams.timeout );
1080  }
1081 
1082  case kXR_fattr:
1083  {
1084  return XAttrImpl( req->fattr.subcode, req->fattr.numattr, req->fattr.dlen,
1085  msg->GetBuffer( sizeof(ClientRequestHdr ) ), handler );
1086  }
1087 
1088  default:
1089  {
1091  }
1092  }
1093  }
struct ClientTruncateRequest truncate
Definition: XProtocol.hh:875
struct ClientFattrRequest fattr
Definition: XProtocol.hh:854
kXR_int64 offset
Definition: XProtocol.hh:646
@ kXR_virtReadv
Definition: XProtocol.hh:150
kXR_unt16 options
Definition: XProtocol.hh:481
struct ClientOpenRequest open
Definition: XProtocol.hh:860
struct ClientRequestHdr header
Definition: XProtocol.hh:846
kXR_unt16 requestid
Definition: XProtocol.hh:157
@ kXR_read
Definition: XProtocol.hh:125
@ kXR_open
Definition: XProtocol.hh:122
@ kXR_writev
Definition: XProtocol.hh:143
@ kXR_readv
Definition: XProtocol.hh:137
@ kXR_sync
Definition: XProtocol.hh:128
@ kXR_fattr
Definition: XProtocol.hh:132
@ kXR_write
Definition: XProtocol.hh:131
@ kXR_truncate
Definition: XProtocol.hh:140
@ kXR_stat
Definition: XProtocol.hh:129
@ kXR_close
Definition: XProtocol.hh:115
struct ClientReadRequest read
Definition: XProtocol.hh:867
kXR_unt16 mode
Definition: XProtocol.hh:480
kXR_int64 offset
Definition: XProtocol.hh:808
struct ClientWriteRequest write
Definition: XProtocol.hh:876
kXR_int32 rlen
Definition: XProtocol.hh:647
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Stat(ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus ReadV(uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus WriteV(uint64_t offset, ChunkList *chunks, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
uint16_t GetVirtReqID() const
Get virtual request ID for the message.
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
std::vector< ChunkInfo > ChunkList
List of chunks.
const uint16_t errNotSupported
Definition: XrdClStatus.hh:62

References XrdCl::MessageSendParams::chunkList, Close(), ClientFattrRequest::dlen, ClientWriteRequest::dlen, XrdCl::errNotSupported, ClientRequest::fattr, XrdCl::Buffer::GetBuffer(), XrdCl::URL::GetURL(), XrdCl::Message::GetVirtReqID(), ClientRequest::header, kXR_close, kXR_fattr, kXR_open, kXR_read, kXR_readv, kXR_stat, kXR_sync, kXR_truncate, kXR_virtReadv, kXR_write, kXR_writev, ClientOpenRequest::mode, ClientFattrRequest::numattr, ClientReadRequest::offset, ClientTruncateRequest::offset, ClientWriteRequest::offset, ClientRequest::open, Open(), ClientOpenRequest::options, ClientRequest::read, Read(), ReadV(), ClientRequestHdr::requestid, ClientReadRequest::rlen, XrdOucIOVec::size, Stat(), XrdCl::stError, ClientFattrRequest::subcode, Sync(), XrdCl::MessageSendParams::timeout, ClientRequest::truncate, Truncate(), VectorRead(), VectorWrite(), ClientRequest::write, Write(), and WriteV().

+ Here is the call graph for this function:

◆ Fcntl()

XRootDStatus XrdCl::LocalFileHandler::Fcntl ( const Buffer arg,
ResponseHandler handler,
uint16_t  timeout = 0 
)

Performs a custom operation on an open file - 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 603 of file XrdClLocalFileHandler.cc.

605  {
607  }

References XrdCl::errNotSupported, and XrdCl::stError.

◆ GetHostList()

const HostList& XrdCl::LocalFileHandler::GetHostList ( )
inline

Definition at line 306 of file XrdClLocalFileHandler.hh.

307  {
308  return pHostList;
309  }

◆ GetXAttr()

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

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 649 of file XrdClLocalFileHandler.cc.

652  {
653  XrdSysXAttr *xattr = XrdSysFAttr::Xat;
654  std::vector<XAttr> response;
655 
656  auto itr = attrs.begin();
657  for( ; itr != attrs.end(); ++itr )
658  {
659  std::string name = *itr;
660  std::unique_ptr<char[]> buffer;
661 
662  int size = xattr->Get( name.c_str(), 0, 0, 0, fd );
663  if( size < 0 )
664  {
665  XRootDStatus status( stError, errLocalError, -size );
666  response.push_back( XAttr( *itr, "", status ) );
667  continue;
668  }
669  buffer.reset( new char[size] );
670  int ret = xattr->Get( name.c_str(), buffer.get(), size, 0, fd );
671 
672  XRootDStatus status;
673  std::string value;
674 
675  if( ret >= 0 )
676  value.append( buffer.get(), ret );
677  else if( ret < 0 )
678  status = XRootDStatus( stError, errLocalError, -ret );
679 
680  response.push_back( XAttr( *itr, value, status ) );
681  }
682 
683  AnyObject *resp = new AnyObject();
684  resp->Set( new std::vector<XAttr>( std::move( response ) ) );
685 
686  return QueueTask( new XRootDStatus(), resp, handler );
687  }
virtual int Get(const char *Aname, void *Aval, int Avsz, const char *Path, int fd=-1)=0
Extended attributes with status.

References XrdCl::errLocalError, XrdSysXAttr::Get(), QueueTask(), XrdCl::AnyObject::Set(), XrdCl::stError, and XrdSysFAttr::Xat.

+ Here is the call graph for this function:

◆ ListXAttr()

XRootDStatus XrdCl::LocalFileHandler::ListXAttr ( ResponseHandler handler,
uint16_t  timeout = 0 
)

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 719 of file XrdClLocalFileHandler.cc.

721  {
722  XrdSysXAttr *xattr = XrdSysFAttr::Xat;
723  std::vector<XAttr> response;
724 
725  XrdSysXAttr::AList *alist = 0;
726  int err = xattr->List( &alist, 0, fd, 1 );
727 
728  if( err < 0 )
729  {
730  XRootDStatus *status = new XRootDStatus( stError, XProtocol::mapError( -err ) );
731  return QueueTask( status, 0, handler );
732  }
733 
734  XrdSysXAttr::AList *ptr = alist;
735  while( ptr )
736  {
737  std::string name( ptr->Name, ptr->Nlen );
738  int vlen = ptr->Vlen;
739  ptr = ptr->Next;
740 
741  std::unique_ptr<char[]> buffer( new char[vlen] );
742  int ret = xattr->Get( name.c_str(),
743  buffer.get(), vlen, 0, fd );
744 
745  std::string value = ret >= 0 ? std::string( buffer.get(), ret ) :
746  std::string();
747  XRootDStatus status = ret >= 0 ? XRootDStatus() :
749  response.push_back( XAttr( name, value, status ) );
750  }
751  xattr->Free( alist );
752 
753  AnyObject *resp = new AnyObject();
754  resp->Set( new std::vector<XAttr>( std::move( response ) ) );
755 
756  return QueueTask( new XRootDStatus(), resp, handler );
757  }
static int mapError(int rc)
Definition: XProtocol.hh:1362
char Name[1]
Start of the name (size of struct is dynamic)
Definition: XrdSysXAttr.hh:56
int Vlen
The length of the attribute value;.
Definition: XrdSysXAttr.hh:54
virtual int List(AList **aPL, const char *Path, int fd=-1, int getSz=0)=0
int Nlen
The length of the attribute name that follows.
Definition: XrdSysXAttr.hh:55
virtual void Free(AList *aPL)=0
AList * Next
-> next element.
Definition: XrdSysXAttr.hh:53

References XrdCl::errLocalError, XrdSysXAttr::Free(), XrdSysXAttr::Get(), XrdSysXAttr::List(), XProtocol::mapError(), XrdSysXAttr::AList::Name, XrdSysXAttr::AList::Next, XrdSysXAttr::AList::Nlen, QueueTask(), XrdCl::AnyObject::Set(), XrdCl::stError, XrdSysXAttr::AList::Vlen, and XrdSysFAttr::Xat.

+ Here is the call graph for this function:

◆ MkdirPath()

XRootDStatus XrdCl::LocalFileHandler::MkdirPath ( const std::string &  path)
static

creates the directories specified in path

Parameters
pathspecifies which directories are to be created
Returns
status of the mkdir system call

Definition at line 786 of file XrdClLocalFileHandler.cc.

787  {
788  // first find the most up-front component that exists
789  size_t pos = path.rfind( '/' );
790  while( pos != std::string::npos && pos != 0 )
791  {
792  std::string tmp = path.substr( 0, pos );
793  struct stat st;
794  int rc = lstat( tmp.c_str(), &st );
795  if( rc == 0 ) break;
796  if( errno != ENOENT )
797  return XRootDStatus( stError, errLocalError, errno );
798  pos = path.rfind( '/', pos - 1 );
799  }
800 
801  pos = path.find( '/', pos + 1 );
802  while( pos != std::string::npos && pos != 0 )
803  {
804  std::string tmp = path.substr( 0, pos );
805  if( mkdir( tmp.c_str(), 0755 ) )
806  {
807  if( errno != EEXIST )
808  return XRootDStatus( stError, errLocalError, errno );
809  }
810  pos = path.find( '/', pos + 1 );
811  }
812  return XRootDStatus();
813  }
int mkdir(const char *path, mode_t mode)
#define stat(a, b)
Definition: XrdPosix.hh:101

References XrdCl::errLocalError, mkdir(), stat, and XrdCl::stError.

+ Here is the call graph for this function:

◆ Open() [1/2]

XRootDStatus XrdCl::LocalFileHandler::Open ( const std::string &  url,
uint16_t  flags,
uint16_t  mode,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 242 of file XrdClLocalFileHandler.cc.

244  {
245  AnyObject *resp = 0;
246  XRootDStatus st = OpenImpl( url, flags, mode, resp );
247  if( !st.IsOK() && st.code != errLocalError )
248  return st;
249 
250  return QueueTask( new XRootDStatus( st ), resp, handler );
251  }
Open operation (.
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 XrdCl::Status::code, XrdCl::errLocalError, XrdCl::Status::IsOK(), and QueueTask().

Referenced by ExecRequest().

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

◆ Open() [2/2]

XRootDStatus XrdCl::LocalFileHandler::Open ( const URL url,
const Message req,
AnyObject *&  resp 
)

Handle local redirect to given URL triggered by the given request.

Definition at line 253 of file XrdClLocalFileHandler.cc.

254  {
255  const ClientOpenRequest* request =
256  reinterpret_cast<const ClientOpenRequest*>( req->GetBuffer() );
257  uint16_t flags = ntohs( request->options );
258  uint16_t mode = ntohs( request->mode );
259  return OpenImpl( url->GetURL(), flags, mode, resp );
260  }

References XrdCl::Buffer::GetBuffer(), XrdCl::URL::GetURL(), ClientOpenRequest::mode, and ClientOpenRequest::options.

+ Here is the call graph for this function:

◆ QueueTask()

XRootDStatus XrdCl::LocalFileHandler::QueueTask ( XRootDStatus st,
AnyObject obj,
ResponseHandler handler 
)

Queues a task to the jobmanager

Parameters
stthe status of the file operation
objthe object holding data like open-, chunk- or vreadinfo
handlerhandler to be notified when the response arrives
Returns
status of the operation

Definition at line 764 of file XrdClLocalFileHandler.cc.

766  {
767  // if it is simply the sync handler we can release the semaphore
768  // and return there is no need to execute this in the thread-pool
769  if (SyncResponseHandler *syncHandler = dynamic_cast<SyncResponseHandler*>(handler)) {
770  syncHandler->HandleResponse( st, resp );
771  return XRootDStatus();
772  }
773 
774  if (auto postmaster = DefaultEnv::GetPostMaster()) {
775  HostList *hosts = pHostList.empty() ? 0 : new HostList( pHostList );
776  LocalFileTask *task = new LocalFileTask( st, resp, hosts, handler );
777  postmaster->GetJobManager()->QueueJob( task );
778  }
779  return XRootDStatus();
780  }
static PostMaster * GetPostMaster()
Get default post master.
Synchronize the response.
std::vector< HostInfo > HostList

References XrdCl::DefaultEnv::GetPostMaster().

Referenced by Close(), DelXAttr(), GetXAttr(), ListXAttr(), Open(), Read(), ReadV(), SetXAttr(), Stat(), Sync(), Truncate(), VectorRead(), VectorWrite(), Write(), and WriteV().

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

◆ Read()

XRootDStatus XrdCl::LocalFileHandler::Read ( uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 316 of file XrdClLocalFileHandler.cc.

318  {
319 #if defined(__APPLE__)
320  Log *log = DefaultEnv::GetLog();
321  int read = 0;
322  if( ( read = pread( fd, buffer, size, offset ) ) == -1 )
323  {
324  log->Error( FileMsg, "Read: failed %s", XrdSysE2T( errno ) );
325  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
326  return QueueTask( error, 0, handler );
327  }
328  ChunkInfo *chunk = new ChunkInfo( offset, read, buffer );
329  AnyObject *resp = new AnyObject();
330  resp->Set( chunk );
331  return QueueTask( new XRootDStatus(), resp, handler );
332 #else
333  AioCtx *ctx = new AioCtx( pHostList, handler );
334  ctx->SetRead( fd, offset, size, buffer );
335 
336  int rc = aio_read( *ctx );
337 
338  if( rc < 0 )
339  {
340  Log *log = DefaultEnv::GetLog();
341  log->Error( FileMsg, "Read: failed %s", XrdSysE2T( errno ) );
342  return XRootDStatus( stError, errLocalError, errno );
343  }
344 
345  return XRootDStatus();
346 #endif
347  }
ssize_t read(int fildes, void *buf, size_t nbyte)
#define pread(a, b, c, d)
Definition: XrdPosix.hh:80
Describe a data chunk for vector read.

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), pread, QueueTask(), read(), XrdCl::AnyObject::Set(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ ReadV()

XRootDStatus XrdCl::LocalFileHandler::ReadV ( uint64_t  offset,
struct iovec *  iov,
int  iovcnt,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 353 of file XrdClLocalFileHandler.cc.

358  {
359  Log *log = DefaultEnv::GetLog();
360 #if defined(__APPLE__)
361  ssize_t ret = lseek( fd, offset, SEEK_SET );
362  if( ret >= 0 )
363  ret = readv( fd, iov, iovcnt );
364 #else
365  ssize_t ret = preadv( fd, iov, iovcnt, offset );
366 #endif
367  if( ret == -1 )
368  {
369  log->Error( FileMsg, "ReadV: failed %s", XrdSysE2T( errno ) );
370  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
371  return QueueTask( error, 0, handler );
372  }
373  VectorReadInfo *info = new VectorReadInfo();
374  info->SetSize( ret );
375  uint64_t choff = offset;
376  uint32_t left = ret;
377  for( int i = 0; i < iovcnt; ++i )
378  {
379  uint32_t chlen = iov[i].iov_len;
380  if( chlen > left ) chlen = left;
381  info->GetChunks().emplace_back( choff, chlen, iov[i].iov_base);
382  left -= chlen;
383  choff += chlen;
384  }
385  AnyObject *resp = new AnyObject();
386  resp->Set( info );
387  return QueueTask( new XRootDStatus(), resp, handler );
388  }
ssize_t readv(int fildes, const struct iovec *iov, int iovcnt)
#define lseek(a, b, c)
Definition: XrdPosix.hh:52
void SetSize(uint32_t size)
Set size.
ChunkList & GetChunks()
Get chunks.

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::VectorReadInfo::GetChunks(), XrdCl::DefaultEnv::GetLog(), lseek, QueueTask(), readv(), XrdCl::AnyObject::Set(), XrdCl::VectorReadInfo::SetSize(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ SetHostList()

void XrdCl::LocalFileHandler::SetHostList ( const HostList hostList)
inline

Definition at line 301 of file XrdClLocalFileHandler.hh.

302  {
303  pHostList = hostList;
304  }

◆ SetXAttr()

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

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 621 of file XrdClLocalFileHandler.cc.

624  {
625  XrdSysXAttr *xattr = XrdSysFAttr::Xat;
626  std::vector<XAttrStatus> response;
627 
628  auto itr = attrs.begin();
629  for( ; itr != attrs.end(); ++itr )
630  {
631  std::string name = std::get<xattr_name>( *itr );
632  std::string value = std::get<xattr_value>( *itr );
633  int err = xattr->Set( name.c_str(), value.c_str(), value.size(), 0, fd );
634  XRootDStatus status = err < 0 ? XRootDStatus( stError, errLocalError, -err ) :
635  XRootDStatus();
636 
637  response.push_back( XAttrStatus( name, status ) );
638  }
639 
640  AnyObject *resp = new AnyObject();
641  resp->Set( new std::vector<XAttrStatus>( std::move( response ) ) );
642 
643  return QueueTask( new XRootDStatus(), resp, handler );
644  }
virtual int Set(const char *Aname, const void *Aval, int Avsz, const char *Path, int fd=-1, int isNew=0)=0

References XrdCl::errLocalError, QueueTask(), XrdSysXAttr::Set(), XrdCl::AnyObject::Set(), XrdCl::stError, and XrdSysFAttr::Xat.

+ Here is the call graph for this function:

◆ Stat()

XRootDStatus XrdCl::LocalFileHandler::Stat ( ResponseHandler handler,
uint16_t  timeout = 0 
)

Obtain status information for this file - async

Parameters
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 282 of file XrdClLocalFileHandler.cc.

284  {
285  Log *log = DefaultEnv::GetLog();
286 
287  struct stat ssp;
288  if( fstat( fd, &ssp ) == -1 )
289  {
290  log->Error( FileMsg, "Stat: failed fd: %i %s", fd, XrdSysE2T( errno ) );
291  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
292  return QueueTask( error, 0, handler );
293  }
294  std::ostringstream data;
295  data << ssp.st_dev << " " << ssp.st_size << " " << ssp.st_mode << " "
296  << ssp.st_mtime;
297  log->Debug( FileMsg, "%s", data.str().c_str() );
298 
299  StatInfo *statInfo = new StatInfo();
300  if( !statInfo->ParseServerResponse( data.str().c_str() ) )
301  {
302  log->Error( FileMsg, "Stat: ParseServerResponse failed." );
303  delete statInfo;
305  0, handler );
306  }
307 
308  AnyObject *resp = new AnyObject();
309  resp->Set( statInfo );
310  return QueueTask( new XRootDStatus(), resp, handler );
311  }
@ kXR_FSError
Definition: XProtocol.hh:995
#define fstat(a, b)
Definition: XrdPosix.hh:62
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
Object stat info.
bool ParseServerResponse(const char *data)
Parse server response and fill up the object.

References XrdCl::Log::Debug(), XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, fstat, XrdCl::DefaultEnv::GetLog(), kXR_FSError, XrdCl::StatInfo::ParseServerResponse(), QueueTask(), XrdCl::AnyObject::Set(), stat, XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ Sync()

XRootDStatus XrdCl::LocalFileHandler::Sync ( ResponseHandler handler,
uint16_t  timeout = 0 
)

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 434 of file XrdClLocalFileHandler.cc.

436  {
437 #if defined(__APPLE__)
438  if( fsync( fd ) )
439  {
440  Log *log = DefaultEnv::GetLog();
441  log->Error( FileMsg, "Sync: failed %s", XrdSysE2T( errno ) );
443  XProtocol::mapError( errno ),
444  XrdSysE2T( errno ) );
445  return QueueTask( error, 0, handler );
446  }
447  return QueueTask( new XRootDStatus(), 0, handler );
448 #else
449  AioCtx *ctx = new AioCtx( pHostList, handler );
450  ctx->SetFsync( fd );
451  int rc = aio_fsync( O_SYNC, *ctx );
452  if( rc < 0 )
453  {
454  Log *log = DefaultEnv::GetLog();
455  log->Error( FileMsg, "Sync: failed %s", XrdSysE2T( errno ) );
456  return XRootDStatus( stError, errLocalError, errno );
457  }
458 #endif
459  return XRootDStatus();
460  }
int fsync(int fildes)
const uint16_t errOSError
Definition: XrdClStatus.hh:61

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::errOSError, XrdCl::FileMsg, fsync(), XrdCl::DefaultEnv::GetLog(), XProtocol::mapError(), QueueTask(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ Truncate()

XRootDStatus XrdCl::LocalFileHandler::Truncate ( uint64_t  size,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 465 of file XrdClLocalFileHandler.cc.

467  {
468  if( ftruncate( fd, size ) )
469  {
470  Log *log = DefaultEnv::GetLog();
471  log->Error( FileMsg, "Truncate: failed, file descriptor: %i, %s", fd,
472  XrdSysE2T( errno ) );
473  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
474  return QueueTask( error, 0, handler );
475  }
476 
477  return QueueTask( new XRootDStatus( stOK ), 0, handler );
478  }
#define ftruncate(a, b)
Definition: XrdPosix.hh:70
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, ftruncate, XrdCl::DefaultEnv::GetLog(), QueueTask(), XrdCl::stError, XrdCl::stOK, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ VectorRead()

XRootDStatus XrdCl::LocalFileHandler::VectorRead ( const ChunkList chunks,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 483 of file XrdClLocalFileHandler.cc.

485  {
486  std::unique_ptr<VectorReadInfo> info( new VectorReadInfo() );
487  size_t totalSize = 0;
488  bool useBuffer( buffer );
489 
490  for( auto itr = chunks.begin(); itr != chunks.end(); ++itr )
491  {
492  auto &chunk = *itr;
493  if( !useBuffer )
494  buffer = chunk.buffer;
495  ssize_t bytesRead = pread( fd, buffer, chunk.length,
496  chunk.offset );
497  if( bytesRead < 0 )
498  {
499  Log *log = DefaultEnv::GetLog();
500  log->Error( FileMsg, "VectorRead: failed, file descriptor: %i, %s",
501  fd, XrdSysE2T( errno ) );
502  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
503  return QueueTask( error, 0, handler );
504  }
505  totalSize += bytesRead;
506  info->GetChunks().push_back( ChunkInfo( chunk.offset, bytesRead, buffer ) );
507  if( useBuffer )
508  buffer = reinterpret_cast<char*>( buffer ) + bytesRead;
509  }
510 
511  info->SetSize( totalSize );
512  AnyObject *resp = new AnyObject();
513  resp->Set( info.release() );
514  return QueueTask( new XRootDStatus(), resp, handler );
515  }

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), pread, QueueTask(), XrdCl::AnyObject::Set(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ VectorWrite()

XRootDStatus XrdCl::LocalFileHandler::VectorWrite ( const ChunkList chunks,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 520 of file XrdClLocalFileHandler.cc.

522  {
523 
524  for( auto itr = chunks.begin(); itr != chunks.end(); ++itr )
525  {
526  auto &chunk = *itr;
527  ssize_t bytesWritten = pwrite( fd, chunk.buffer, chunk.length,
528  chunk.offset );
529  if( bytesWritten < 0 )
530  {
531  Log *log = DefaultEnv::GetLog();
532  log->Error( FileMsg, "VectorWrite: failed, file descriptor: %i, %s",
533  fd, XrdSysE2T( errno ) );
534  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
535  return QueueTask( error, 0, handler );
536  }
537  }
538 
539  return QueueTask( new XRootDStatus(), 0, handler );
540  }
#define pwrite(a, b, c, d)
Definition: XrdPosix.hh:107

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), pwrite, QueueTask(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ Visa()

XRootDStatus XrdCl::LocalFileHandler::Visa ( ResponseHandler handler,
uint16_t  timeout = 0 
)

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 612 of file XrdClLocalFileHandler.cc.

614  {
616  }

References XrdCl::errNotSupported, and XrdCl::stError.

◆ Write()

XRootDStatus XrdCl::LocalFileHandler::Write ( uint64_t  offset,
uint32_t  size,
const void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)

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 393 of file XrdClLocalFileHandler.cc.

395  {
396 #if defined(__APPLE__)
397  const char *buff = reinterpret_cast<const char*>( buffer );
398  size_t bytesWritten = 0;
399  while( bytesWritten < size )
400  {
401  ssize_t ret = pwrite( fd, buff, size, offset );
402  if( ret < 0 )
403  {
404  Log *log = DefaultEnv::GetLog();
405  log->Error( FileMsg, "Write: failed %s", XrdSysE2T( errno ) );
406  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
407  return QueueTask( error, 0, handler );
408  }
409  offset += ret;
410  buff += ret;
411  bytesWritten += ret;
412  }
413  return QueueTask( new XRootDStatus(), 0, handler );
414 #else
415  AioCtx *ctx = new AioCtx( pHostList, handler );
416  ctx->SetWrite( fd, offset, size, buffer );
417 
418  int rc = aio_write( *ctx );
419 
420  if( rc < 0 )
421  {
422  Log *log = DefaultEnv::GetLog();
423  log->Error( FileMsg, "Write: failed %s", XrdSysE2T( errno ) );
424  return XRootDStatus( stError, errLocalError, errno );
425  }
426 
427  return XRootDStatus();
428 #endif
429  }

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), pwrite, QueueTask(), XrdCl::stError, and XrdSysE2T().

Referenced by ExecRequest().

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

◆ WriteV()

XRootDStatus XrdCl::LocalFileHandler::WriteV ( uint64_t  offset,
ChunkList chunks,
ResponseHandler handler,
uint16_t  timeout = 0 
)

Write scattered buffers in one operation - async

Parameters
offsetoffset from the beginning of the file
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 545 of file XrdClLocalFileHandler.cc.

549  {
550  size_t iovcnt = chunks->size();
551  iovec iovcp[iovcnt];
552  ssize_t size = 0;
553  for( size_t i = 0; i < iovcnt; ++i )
554  {
555  iovcp[i].iov_base = (*chunks)[i].buffer;
556  iovcp[i].iov_len = (*chunks)[i].length;
557  size += (*chunks)[i].length;
558  }
559  iovec *iovptr = iovcp;
560 
561  ssize_t bytesWritten = 0;
562  while( bytesWritten < size )
563  {
564 #ifdef __APPLE__
565  ssize_t ret = lseek( fd, offset, SEEK_SET );
566  if( ret >= 0 )
567  ret = writev( fd, iovptr, iovcnt );
568 #else
569  ssize_t ret = pwritev( fd, iovptr, iovcnt, offset );
570 #endif
571  if( ret < 0 )
572  {
573  Log *log = DefaultEnv::GetLog();
574  log->Error( FileMsg, "WriteV: failed %s", XrdSysE2T( errno ) );
575  XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
576  return QueueTask( error, 0, handler );
577  }
578 
579  bytesWritten += ret;
580  while( ret )
581  {
582  if( size_t( ret ) > iovptr[0].iov_len )
583  {
584  ret -= iovptr[0].iov_len;
585  --iovcnt;
586  ++iovptr;
587  }
588  else
589  {
590  iovptr[0].iov_len -= ret;
591  iovptr[0].iov_base = reinterpret_cast<char*>( iovptr[0].iov_base ) + ret;
592  ret = 0;
593  }
594  }
595  }
596 
597  return QueueTask( new XRootDStatus(), 0, handler );
598  }
ssize_t writev(int fildes, const struct iovec *iov, int iovcnt)

References XrdCl::errLocalError, XrdCl::Log::Error(), XrdCl::FileMsg, XrdCl::DefaultEnv::GetLog(), lseek, QueueTask(), XrdCl::stError, writev(), and XrdSysE2T().

Referenced by ExecRequest().

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

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