XRootD
Loading...
Searching...
No Matches
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.
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.
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 230 of file XrdClLocalFileHandler.cc.

230 :
231 fd( -1 )
232 {
233 }

◆ ~LocalFileHandler()

XrdCl::LocalFileHandler::~LocalFileHandler ( )

Definition at line 238 of file XrdClLocalFileHandler.cc.

239 {
240
241 }

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

271 {
272 if( close( fd ) == -1 )
273 {
274 Log *log = DefaultEnv::GetLog();
275 log->Error( FileMsg, "Close: file fd: %i %s", fd, XrdSysE2T( errno ) );
276 XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
277 return QueueTask( error, 0, handler );
278 }
279
280 return QueueTask( new XRootDStatus(), 0, handler );
281 }
#define close(a)
Definition XrdPosix.hh:43
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
static Log * GetLog()
Get default log.
XRootDStatus QueueTask(XRootDStatus *st, AnyObject *obj, ResponseHandler *handler)
const uint16_t stError
An error occurred that could potentially be retried.
const uint64_t FileMsg
const uint16_t errLocalError
XrdSysError Log
Definition XrdConfig.cc:112

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

699 {
700 XrdSysXAttr *xattr = XrdSysFAttr::Xat;
701 std::vector<XAttrStatus> response;
702
703 auto itr = attrs.begin();
704 for( ; itr != attrs.end(); ++itr )
705 {
706 std::string name = *itr;
707 int err = xattr->Del( name.c_str(), 0, fd );
708 XRootDStatus status = err < 0 ? XRootDStatus( stError, errLocalError, -err ) :
709 XRootDStatus();
710
711 response.push_back( XAttrStatus( name, status ) );
712 }
713
714 AnyObject *resp = new AnyObject();
715 resp->Set( new std::vector<XAttrStatus>( std::move( response ) ) );
716
717 return QueueTask( new XRootDStatus(), resp, handler );
718 }
static XrdSysXAttr * Xat
virtual int Del(const char *Aname, const char *Path, int fd=-1)=0

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

1007 {
1008 ClientRequest *req = reinterpret_cast<ClientRequest*>( msg->GetBuffer() );
1009
1010 switch( req->header.requestid )
1011 {
1012 case kXR_open:
1013 {
1014 XRootDStatus st = Open( url.GetURL(), req->open.options,
1015 req->open.mode, handler, sendParams.timeout );
1016 delete msg; // in case of other operations msg is owned by the handler
1017 return st;
1018 }
1019
1020 case kXR_close:
1021 {
1022 return Close( handler, sendParams.timeout );
1023 }
1024
1025 case kXR_stat:
1026 {
1027 return Stat( handler, sendParams.timeout );
1028 }
1029
1030 case kXR_read:
1031 {
1032 if( msg->GetVirtReqID() == kXR_virtReadv )
1033 {
1034 auto &chunkList = *sendParams.chunkList;
1035 struct iovec iov[chunkList.size()];
1036 for( size_t i = 0; i < chunkList.size() ; ++i )
1037 {
1038 iov[i].iov_base = chunkList[i].buffer;
1039 iov[i].iov_len = chunkList[i].length;
1040 }
1041 return ReadV( chunkList.front().offset, iov, chunkList.size(),
1042 handler, sendParams.timeout );
1043 }
1044
1045 return Read( req->read.offset, req->read.rlen,
1046 sendParams.chunkList->front().buffer,
1047 handler, sendParams.timeout );
1048 }
1049
1050 case kXR_write:
1051 {
1052 ChunkList *chunks = sendParams.chunkList;
1053 if( chunks->size() == 1 )
1054 {
1055 // it's an ordinary write
1056 return Write( req->write.offset, req->write.dlen,
1057 chunks->front().buffer, handler,
1058 sendParams.timeout );
1059 }
1060 // it's WriteV call
1061 return WriteV( req->write.offset, sendParams.chunkList,
1062 handler, sendParams.timeout );
1063 }
1064
1065 case kXR_sync:
1066 {
1067 return Sync( handler, sendParams.timeout );
1068 }
1069
1070 case kXR_truncate:
1071 {
1072 return Truncate( req->truncate.offset, handler, sendParams.timeout );
1073 }
1074
1075 case kXR_writev:
1076 {
1077 return VectorWrite( *sendParams.chunkList, handler,
1078 sendParams.timeout );
1079 }
1080
1081 case kXR_readv:
1082 {
1083 return VectorRead( *sendParams.chunkList, 0,
1084 handler, sendParams.timeout );
1085 }
1086
1087 case kXR_fattr:
1088 {
1089 return XAttrImpl( req->fattr.subcode, req->fattr.numattr, req->fattr.dlen,
1090 msg->GetBuffer( sizeof(ClientRequestHdr ) ), handler );
1091 }
1092
1093 default:
1094 {
1095 return XRootDStatus( stError, errNotSupported );
1096 }
1097 }
1098 }
struct ClientTruncateRequest truncate
Definition XProtocol.hh:875
struct ClientFattrRequest fattr
Definition XProtocol.hh:854
@ 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
struct ClientWriteRequest write
Definition XProtocol.hh:876
struct stat Stat
Definition XrdCks.cc:49
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 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)
std::vector< ChunkInfo > ChunkList
List of chunks.
const uint16_t errNotSupported

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, Open(), ClientRequest::open, ClientOpenRequest::options, Read(), ClientRequest::read, ReadV(), ClientRequestHdr::requestid, ClientReadRequest::rlen, XrdOucIOVec::size, Stat, XrdCl::stError, ClientFattrRequest::subcode, Sync(), XrdCl::MessageSendParams::timeout, Truncate(), ClientRequest::truncate, VectorRead(), VectorWrite(), Write(), ClientRequest::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 607 of file XrdClLocalFileHandler.cc.

609 {
610 return XRootDStatus( stError, errNotSupported );
611 }

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

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

References XrdCl::errLocalError, XrdSysXAttr::Get(), XrdCl::NullRef< Response >::value, 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 723 of file XrdClLocalFileHandler.cc.

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

References XrdCl::errLocalError, XrdSysXAttr::Free(), XrdSysXAttr::Get(), XrdSysXAttr::List(), XProtocol::mapError(), XrdSysXAttr::AList::Name, XrdSysXAttr::AList::Next, XrdSysXAttr::AList::Nlen, XrdCl::NullRef< Response >::value, 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 791 of file XrdClLocalFileHandler.cc.

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

References XrdCl::errLocalError, lstat(), 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 246 of file XrdClLocalFileHandler.cc.

248 {
249 AnyObject *resp = 0;
250 XRootDStatus st = OpenImpl( url, flags, mode, resp );
251 if( !st.IsOK() && st.code != errLocalError )
252 return st;
253
254 return QueueTask( new XRootDStatus( st ), resp, handler );
255 }

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

258 {
259 const ClientOpenRequest* request =
260 reinterpret_cast<const ClientOpenRequest*>( req->GetBuffer() );
261 uint16_t flags = ntohs( request->options );
262 uint16_t mode = ntohs( request->mode );
263 return OpenImpl( url->GetURL(), flags, mode, resp );
264 }

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

770 {
771 // if it is simply the sync handler we can release the semaphore
772 // and return there is no need to execute this in the thread-pool
773 SyncResponseHandler *syncHandler =
774 dynamic_cast<SyncResponseHandler*>( handler );
775 if( syncHandler || DefaultEnv::GetPostMaster() == nullptr )
776 {
777 syncHandler->HandleResponse( st, resp );
778 return XRootDStatus();
779 }
780
781 HostList *hosts = pHostList.empty() ? 0 : new HostList( pHostList );
782 LocalFileTask *task = new LocalFileTask( st, resp, hosts, handler );
784 return XRootDStatus();
785 }
static PostMaster * GetPostMaster()
Get default post master.
void QueueJob(Job *job, void *arg=0)
Add a job to be run.
JobManager * GetJobManager()
Get the job manager object user by the post master.
std::vector< HostInfo > HostList

References XrdCl::PostMaster::GetJobManager(), XrdCl::DefaultEnv::GetPostMaster(), XrdCl::SyncResponseHandler::HandleResponse(), and XrdCl::JobManager::QueueJob().

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

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

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

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

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

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

References XrdCl::errLocalError, XrdCl::NullRef< Response >::value, QueueTask(), XrdCl::AnyObject::Set(), XrdSysXAttr::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 286 of file XrdClLocalFileHandler.cc.

288 {
289 Log *log = DefaultEnv::GetLog();
290
291 struct stat ssp;
292 if( fstat( fd, &ssp ) == -1 )
293 {
294 log->Error( FileMsg, "Stat: failed fd: %i %s", fd, XrdSysE2T( errno ) );
295 XRootDStatus *error = new XRootDStatus( stError, errLocalError, errno );
296 return QueueTask( error, 0, handler );
297 }
298 std::ostringstream data;
299 data << ssp.st_dev << " " << ssp.st_size << " " << ssp.st_mode << " "
300 << ssp.st_mtime;
301 log->Debug( FileMsg, "%s", data.str().c_str() );
302
303 StatInfo *statInfo = new StatInfo();
304 if( !statInfo->ParseServerResponse( data.str().c_str() ) )
305 {
306 log->Error( FileMsg, "Stat: ParseServerResponse failed." );
307 delete statInfo;
308 return QueueTask( new XRootDStatus( stError, errLocalError, kXR_FSError ),
309 0, handler );
310 }
311
312 AnyObject *resp = new AnyObject();
313 resp->Set( statInfo );
314 return QueueTask( new XRootDStatus(), resp, handler );
315 }
@ kXR_FSError
Definition XProtocol.hh:995
#define fstat(a, b)
Definition XrdPosix.hh:57

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().

Here is the call 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 438 of file XrdClLocalFileHandler.cc.

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

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

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

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

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

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

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

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

618 {
619 return XRootDStatus( stError, errNotSupported );
620 }

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

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

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

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

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: