xrootd
XrdClFileStateHandler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_FILE_STATE_HANDLER_HH__
26 #define __XRD_CL_FILE_STATE_HANDLER_HH__
27 
30 #include "XrdCl/XrdClFileSystem.hh"
33 #include "XrdCl/XrdClOptional.hh"
35 #include "XrdSys/XrdSysPthread.hh"
36 #include "XrdSys/XrdSysPageSize.hh"
37 
38 #include <list>
39 #include <set>
40 #include <vector>
41 
42 #include <sys/uio.h>
43 #include <stdint.h>
44 
45 namespace
46 {
47  class PgReadHandler;
48  class PgReadRetryHandler;
49  class PgReadSubstitutionHandler;
50  class OpenHandler;
51 }
52 
53 namespace XrdCl
54 {
55  class ResponseHandlerHolder;
56  class Message;
57  class EcHandler;
58 
59  //----------------------------------------------------------------------------
61  //----------------------------------------------------------------------------
62  struct PgReadFlags
63  {
64  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
67  enum Flags
68  {
69  None = 0, //< Nothing
70  Retry = XrdProto::kXR_pgRetry //< Retry reading currupted page
71 
72  };
73  };
75 
76  //----------------------------------------------------------------------------
78  //----------------------------------------------------------------------------
80  {
81  friend class ::PgReadHandler;
82  friend class ::PgReadRetryHandler;
83  friend class ::PgReadSubstitutionHandler;
84  friend class ::OpenHandler;
85 
86  public:
87  //------------------------------------------------------------------------
89  //------------------------------------------------------------------------
91  {
97  CloseInProgress
98  };
99 
100  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  FileStateHandler( FilePlugIn *& plugin );
104 
105  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  FileStateHandler( bool useVirtRedirector, FilePlugIn *& plugin );
112 
113  //------------------------------------------------------------------------
115  //------------------------------------------------------------------------
116  ~FileStateHandler();
117 
118  //------------------------------------------------------------------------
128  //------------------------------------------------------------------------
129  XRootDStatus Open( const std::string &url,
130  uint16_t flags,
131  uint16_t mode,
132  ResponseHandler *handler,
133  uint16_t timeout = 0 );
134 
135  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
144  uint16_t timeout = 0 );
145 
146  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  XRootDStatus Stat( bool force,
158  ResponseHandler *handler,
159  uint16_t timeout = 0 );
160 
161 
162  //------------------------------------------------------------------------
177  //------------------------------------------------------------------------
178  XRootDStatus Read( uint64_t offset,
179  uint32_t size,
180  void *buffer,
181  ResponseHandler *handler,
182  uint16_t timeout = 0 );
183 
184  //------------------------------------------------------------------------
197  //------------------------------------------------------------------------
198  XRootDStatus PgRead( uint64_t offset,
199  uint32_t size,
200  void *buffer,
201  ResponseHandler *handler,
202  uint16_t timeout = 0 );
203 
204  //------------------------------------------------------------------------
215  //------------------------------------------------------------------------
216  XRootDStatus PgReadRetry( uint64_t offset,
217  uint32_t size,
218  size_t pgnb,
219  void *buffer,
220  PgReadHandler *handler,
221  uint16_t timeout = 0 );
222 
223  //------------------------------------------------------------------------
237  //------------------------------------------------------------------------
238  XRootDStatus PgReadImpl( uint64_t offset,
239  uint32_t size,
240  void *buffer,
241  uint16_t flags,
242  ResponseHandler *handler,
243  uint16_t timeout = 0 );
244 
245  //------------------------------------------------------------------------
255  //------------------------------------------------------------------------
256  XRootDStatus Write( uint64_t offset,
257  uint32_t size,
258  const void *buffer,
259  ResponseHandler *handler,
260  uint16_t timeout = 0 );
261 
262  //------------------------------------------------------------------------
272  //------------------------------------------------------------------------
273  XRootDStatus Write( uint64_t offset,
274  Buffer &&buffer,
275  ResponseHandler *handler,
276  uint16_t timeout = 0 );
277 
278  //------------------------------------------------------------------------
291  //------------------------------------------------------------------------
292  XRootDStatus Write( uint64_t offset,
293  uint32_t size,
294  Optional<uint64_t> fdoff,
295  int fd,
296  ResponseHandler *handler,
297  uint16_t timeout = 0 );
298 
299 
300  //------------------------------------------------------------------------
307  //------------------------------------------------------------------------
309  uint16_t timeout = 0 );
310 
311  //------------------------------------------------------------------------
319  //------------------------------------------------------------------------
320  XRootDStatus Truncate( uint64_t size,
321  ResponseHandler *handler,
322  uint16_t timeout = 0 );
323 
324  //------------------------------------------------------------------------
333  //------------------------------------------------------------------------
334  XRootDStatus VectorRead( const ChunkList &chunks,
335  void *buffer,
336  ResponseHandler *handler,
337  uint16_t timeout = 0 );
338 
339  //------------------------------------------------------------------------
347  //------------------------------------------------------------------------
348  XRootDStatus VectorWrite( const ChunkList &chunks,
349  ResponseHandler *handler,
350  uint16_t timeout = 0 );
351 
352  //------------------------------------------------------------------------
362  //------------------------------------------------------------------------
363  XRootDStatus WriteV( uint64_t offset,
364  const struct iovec *iov,
365  int iovcnt,
366  ResponseHandler *handler,
367  uint16_t timeout = 0 );
368 
369  //------------------------------------------------------------------------
379  //------------------------------------------------------------------------
380  XRootDStatus ReadV( uint64_t offset,
381  struct iovec *iov,
382  int iovcnt,
383  ResponseHandler *handler,
384  uint16_t timeout = 0 );
385 
386  //------------------------------------------------------------------------
397  //------------------------------------------------------------------------
398  XRootDStatus Fcntl( const Buffer &arg,
399  ResponseHandler *handler,
400  uint16_t timeout = 0 );
401 
402  //------------------------------------------------------------------------
411  //------------------------------------------------------------------------
413  uint16_t timeout = 0 );
414 
415  //------------------------------------------------------------------------
426  //------------------------------------------------------------------------
427  XRootDStatus SetXAttr( const std::vector<xattr_t> &attrs,
428  ResponseHandler *handler,
429  uint16_t timeout = 0 );
430 
431  //------------------------------------------------------------------------
442  //------------------------------------------------------------------------
443  XRootDStatus GetXAttr( const std::vector<std::string> &attrs,
444  ResponseHandler *handler,
445  uint16_t timeout = 0 );
446 
447  //------------------------------------------------------------------------
458  //------------------------------------------------------------------------
459  XRootDStatus DelXAttr( const std::vector<std::string> &attrs,
460  ResponseHandler *handler,
461  uint16_t timeout = 0 );
462 
463  //------------------------------------------------------------------------
473  //------------------------------------------------------------------------
475  uint16_t timeout = 0 );
476 
477  //------------------------------------------------------------------------
487  //------------------------------------------------------------------------
489  ResponseHandler *handler,
490  uint16_t timeout = 0 );
491 
492  //------------------------------------------------------------------------
502  //------------------------------------------------------------------------
503  XRootDStatus ChkptWrt( uint64_t offset,
504  uint32_t size,
505  const void *buffer,
506  ResponseHandler *handler,
507  uint16_t timeout = 0 );
508 
509  //------------------------------------------------------------------------
519  //------------------------------------------------------------------------
520  XRootDStatus ChkptWrtV( uint64_t offset,
521  const struct iovec *iov,
522  int iovcnt,
523  ResponseHandler *handler,
524  uint16_t timeout = 0 );
525 
526  //------------------------------------------------------------------------
528  //------------------------------------------------------------------------
529  void OnOpen( const XRootDStatus *status,
530  const OpenInfo *openInfo,
531  const HostList *hostList );
532 
533  //------------------------------------------------------------------------
535  //------------------------------------------------------------------------
536  void OnClose( const XRootDStatus *status );
537 
538  //------------------------------------------------------------------------
540  //------------------------------------------------------------------------
541  void OnStateError( XRootDStatus *status,
542  Message *message,
543  ResponseHandler *userHandler,
544  MessageSendParams &sendParams );
545 
546  //------------------------------------------------------------------------
548  //------------------------------------------------------------------------
549  void OnStateRedirection( const std::string &redirectUrl,
550  Message *message,
551  ResponseHandler *userHandler,
552  MessageSendParams &sendParams );
553 
554  //------------------------------------------------------------------------
556  //------------------------------------------------------------------------
557  void OnStateResponse( XRootDStatus *status,
558  Message *message,
559  AnyObject *response,
560  HostList *hostList );
561 
562  //------------------------------------------------------------------------
564  //------------------------------------------------------------------------
565  bool IsOpen() const;
566 
567  //------------------------------------------------------------------------
571  //------------------------------------------------------------------------
572  bool SetProperty( const std::string &name, const std::string &value );
573 
574  //------------------------------------------------------------------------
578  //------------------------------------------------------------------------
579  bool GetProperty( const std::string &name, std::string &value ) const;
580 
581  //------------------------------------------------------------------------
583  //------------------------------------------------------------------------
584  void Lock()
585  {
586  pMutex.Lock();
587  }
588 
589  //------------------------------------------------------------------------
591  //------------------------------------------------------------------------
592  void UnLock()
593  {
594  pMutex.UnLock();
595  }
596 
597  //------------------------------------------------------------------------
599  //------------------------------------------------------------------------
600  void Tick( time_t now );
601 
602  //------------------------------------------------------------------------
604  //------------------------------------------------------------------------
605  void TimeOutRequests( time_t now );
606 
607  //------------------------------------------------------------------------
609  //------------------------------------------------------------------------
610  void AfterForkChild();
611 
612  //------------------------------------------------------------------------
614  //------------------------------------------------------------------------
615  XRootDStatus TryOtherServer( uint16_t timeout );
616 
617  private:
618  //------------------------------------------------------------------------
619  // Helper for queuing messages
620  //------------------------------------------------------------------------
621  struct RequestData
622  {
623  RequestData(): request(0), handler(0) {}
625  const MessageSendParams &p ):
626  request(r), handler(h), params(p) {}
630  };
631  typedef std::list<RequestData> RequestList;
632 
633  //------------------------------------------------------------------------
640  //------------------------------------------------------------------------
641  template<typename T>
642  Status XAttrOperationImpl( kXR_char subcode,
643  kXR_char options,
644  const std::vector<T> &attrs,
645  ResponseHandler *handler,
646  uint16_t timeout = 0 );
647 
648  //------------------------------------------------------------------------
650  //------------------------------------------------------------------------
651  Status SendOrQueue( const URL &url,
652  Message *msg,
653  ResponseHandler *handler,
654  MessageSendParams &sendParams );
655 
656  //------------------------------------------------------------------------
658  //------------------------------------------------------------------------
659  bool IsRecoverable( const XRootDStatus &stataus ) const;
660 
661  //------------------------------------------------------------------------
667  //------------------------------------------------------------------------
668  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
669 
670  //------------------------------------------------------------------------
672  //------------------------------------------------------------------------
673  Status RunRecovery();
674 
675  //------------------------------------------------------------------------
676  // Send a close and ignore the response
677  //------------------------------------------------------------------------
678  XRootDStatus SendClose( uint16_t timeout );
679 
680  //------------------------------------------------------------------------
682  //------------------------------------------------------------------------
683  bool IsReadOnly() const;
684 
685  //------------------------------------------------------------------------
687  //------------------------------------------------------------------------
688  XRootDStatus ReOpenFileAtServer( const URL &url, uint16_t timeout );
689 
690  //------------------------------------------------------------------------
692  //------------------------------------------------------------------------
693  void FailMessage( RequestData rd, XRootDStatus status );
694 
695  //------------------------------------------------------------------------
697  //------------------------------------------------------------------------
698  void FailQueuedMessages( XRootDStatus status );
699 
700  //------------------------------------------------------------------------
702  //------------------------------------------------------------------------
703  void ReSendQueuedMessages();
704 
705  //------------------------------------------------------------------------
707  //------------------------------------------------------------------------
708  void ReWriteFileHandle( Message *msg );
709 
710  //------------------------------------------------------------------------
712  //------------------------------------------------------------------------
714  {
715  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
716  pRBytes = 0;
717  pVRBytes = 0;
718  pWBytes = 0;
719  pVSegs = 0;
720  pRCount = 0;
721  pVRCount = 0;
722  pWCount = 0;
723  pCloseReason = Status();
724  }
725 
726  //------------------------------------------------------------------------
728  //------------------------------------------------------------------------
729  void MonitorClose( const XRootDStatus *status );
730 
731  //------------------------------------------------------------------------
737  //------------------------------------------------------------------------
738  XRootDStatus IssueRequest( const URL &url,
739  Message *msg,
740  ResponseHandler *handler,
741  MessageSendParams &sendParams );
742 
743  //------------------------------------------------------------------------
745  //------------------------------------------------------------------------
746  XRootDStatus WriteKernelBuffer( uint64_t offset,
747  uint32_t length,
748  std::unique_ptr<XrdSys::KernelBuffer> kbuff,
749  ResponseHandler *handler,
750  uint16_t timeout );
751 
761  uint8_t *pFileHandle;
762  uint16_t pOpenMode;
763  uint16_t pOpenFlags;
765  std::set<Message*> pInTheFly;
766  uint64_t pSessionId;
773 
774  //------------------------------------------------------------------------
775  // Monitoring variables
776  //------------------------------------------------------------------------
777  timeval pOpenTime;
778  uint64_t pRBytes;
779  uint64_t pVRBytes;
780  uint64_t pWBytes;
781  uint64_t pVWBytes;
782  uint64_t pVSegs;
783  uint64_t pRCount;
784  uint64_t pVRCount;
785  uint64_t pWCount;
786  uint64_t pVWCount;
788 
789  //------------------------------------------------------------------------
790  // Holds the OpenHanlder used to issue reopen
791  // (there is only only OpenHandler reopening a file at a time)
792  //------------------------------------------------------------------------
793  ResponseHandlerHolder *pReOpenHandler;
794 
795  //------------------------------------------------------------------------
796  // Responsible for file:// operations on the local filesystem
797  //------------------------------------------------------------------------
799 
800  //------------------------------------------------------------------------
801  // Responsible for Writing/Reading erasure-coded files
802  //------------------------------------------------------------------------
804  };
805 }
806 
807 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:780
unsigned char kXR_char
Definition: XPtypes.hh:65
ListXAttrImpl< false > ListXAttr(Ctx< File > file)
Definition: XrdClFileOperations.hh:1155
CloseImpl< false > Close
Definition: XrdClFileOperations.hh:308
FilePlugIn *& pPlugin
Definition: XrdClFileStateHandler.hh:803
Definition: XrdClAnyObject.hh:32
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:584
SetXAttrImpl< false > SetXAttr(Ctx< File > file, Arg< std::string > name, Arg< std::string > value)
Definition: XrdClFileOperations.hh:815
void UnLock()
Unlock the internal lock.
Definition: XrdClFileStateHandler.hh:592
PgRead flags.
Definition: XrdClFileStateHandler.hh:62
Definition: XrdClMessageUtils.hh:131
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:778
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:980
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:766
VectorReadImpl< false > VectorRead
Definition: XrdClFileOperations.hh:559
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
FcntlImpl< false > Fcntl
Definition: XrdClFileOperations.hh:716
uint64_t pVWBytes
Definition: XrdClFileStateHandler.hh:781
Object stat info.
Definition: XrdClXRootDResponses.hh:399
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:785
RequestData()
Definition: XrdClFileStateHandler.hh:623
The file is closed.
Definition: XrdClFileStateHandler.hh:92
Definition: XrdClOptional.hh:43
Message * request
Definition: XrdClFileStateHandler.hh:627
DelXAttrImpl< false > DelXAttr(Ctx< File > file, Arg< std::string > name)
Definition: XrdClFileOperations.hh:1050
ChkptWrtVImpl< false > ChkptWrtV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec >> iov, uint16_t timeout=0)
Factory for creating ChkptWrtVImpl objects.
Definition: XrdClCheckpointOperation.hh:197
SyncImpl< false > Sync
Definition: XrdClFileOperations.hh:458
uint64_t pVSegs
Definition: XrdClFileStateHandler.hh:782
WriteImpl< false > Write(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void *> buffer, uint16_t timeout=0)
Factory for creating WriteImpl objects.
Definition: XrdClFileOperations.hh:414
bool pDoRecoverWrite
Definition: XrdClFileStateHandler.hh:768
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:628
Procedure execution status.
Definition: XrdClStatus.hh:112
static const int kXR_pgRetry
Definition: XProtocol.hh:497
GetXAttrImpl< false > GetXAttr(Ctx< File > file, Arg< std::string > name)
Definition: XrdClFileOperations.hh:933
TruncateImpl< false > Truncate(Ctx< File > file, Arg< uint64_t > size)
Definition: XrdClFileOperations.hh:508
bool pAllowBundledClose
Definition: XrdClFileStateHandler.hh:772
Opening is in progress.
Definition: XrdClFileStateHandler.hh:96
VectorWriteImpl< false > VectorWrite
Definition: XrdClFileOperations.hh:605
Information returned by file open operation.
Definition: XrdClXRootDResponses.hh:852
void ResetMonitoringVars()
Reset monitoring vars.
Definition: XrdClFileStateHandler.hh:713
URL * pWrtRecoveryRedir
Definition: XrdClFileStateHandler.hh:760
Definition: XrdSysPthread.hh:164
bool pDoRecoverRead
Definition: XrdClFileStateHandler.hh:767
LocalFileHandler * pLFileHandler
Definition: XrdClFileStateHandler.hh:798
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:631
Definition: XrdOucIOVec.hh:65
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:765
An interface for file plug-ins.
Definition: XrdClPlugInInterface.hh:38
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:777
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:1045
uint64_t pRCount
Definition: XrdClFileStateHandler.hh:783
MessageSendParams params
Definition: XrdClFileStateHandler.hh:629
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:763
Opening has failed.
Definition: XrdClFileStateHandler.hh:94
Opening has succeeded.
Definition: XrdClFileStateHandler.hh:93
none object for initializing empty Optional
Definition: XrdClOptional.hh:35
Request status.
Definition: XrdClXRootDResponses.hh:218
Definition: XrdClFileStateHandler.hh:70
Definition: XrdClAnyObject.hh:25
ReadImpl< false > Read(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void *> buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
Definition: XrdClFileOperations.hh:264
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
Definition: XrdClFileOperations.hh:358
FileStatus
State of the file.
Definition: XrdClFileStateHandler.hh:90
bool pUseVirtRedirector
Definition: XrdClFileStateHandler.hh:770
ResponseHandlerHolder * pReOpenHandler
Definition: XrdClFileStateHandler.hh:793
Definition: XrdClFileStateHandler.hh:621
Recovering from an error.
Definition: XrdClFileStateHandler.hh:95
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:624
CheckpointImpl< false > Checkpoint(Ctx< File > file, Arg< ChkPtCode > code, uint16_t timeout=0)
Factory for creating ReadImpl objects.
Definition: XrdClCheckpointOperation.hh:72
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:753
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:787
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:786
Flags
PgRead flags.
Definition: XrdClFileStateHandler.hh:67
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:764
Handle an async response.
Definition: XrdClXRootDResponses.hh:1050
Handle the stateful operations.
Definition: XrdClFileStateHandler.hh:79
Definition: XrdClLocalFileHandler.hh:32
OpenImpl< false > Open
Definition: XrdClFileOperations.hh:211
URL representation.
Definition: XrdClURL.hh:30
URL * pFileUrl
Definition: XrdClFileStateHandler.hh:756
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:769
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:784
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:754
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:761
bool pIsChannelEncrypted
Definition: XrdClFileStateHandler.hh:771
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:759
VisaImpl< false > Visa
Definition: XrdClFileOperations.hh:755
WriteVImpl< false > WriteV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec >> iov, uint16_t timeout=0)
Factory for creating WriteVImpl objects.
Definition: XrdClFileOperations.hh:666
URL * pDataServer
Definition: XrdClFileStateHandler.hh:757
ChkptWrtImpl< false > ChkptWrt(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void *> buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
Definition: XrdClCheckpointOperation.hh:129
uint16_t pOpenMode
Definition: XrdClFileStateHandler.hh:762
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:755
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:779
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:752
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:758
Binary blob representation.
Definition: XrdClBuffer.hh:33