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  //------------------------------------------------------------------------
479  //------------------------------------------------------------------------
480  void OnOpen( const XRootDStatus *status,
481  const OpenInfo *openInfo,
482  const HostList *hostList );
483 
484  //------------------------------------------------------------------------
486  //------------------------------------------------------------------------
487  void OnClose( const XRootDStatus *status );
488 
489  //------------------------------------------------------------------------
491  //------------------------------------------------------------------------
492  void OnStateError( XRootDStatus *status,
493  Message *message,
494  ResponseHandler *userHandler,
495  MessageSendParams &sendParams );
496 
497  //------------------------------------------------------------------------
499  //------------------------------------------------------------------------
500  void OnStateRedirection( const std::string &redirectUrl,
501  Message *message,
502  ResponseHandler *userHandler,
503  MessageSendParams &sendParams );
504 
505  //------------------------------------------------------------------------
507  //------------------------------------------------------------------------
508  void OnStateResponse( XRootDStatus *status,
509  Message *message,
510  AnyObject *response,
511  HostList *hostList );
512 
513  //------------------------------------------------------------------------
515  //------------------------------------------------------------------------
516  bool IsOpen() const;
517 
518  //------------------------------------------------------------------------
522  //------------------------------------------------------------------------
523  bool SetProperty( const std::string &name, const std::string &value );
524 
525  //------------------------------------------------------------------------
529  //------------------------------------------------------------------------
530  bool GetProperty( const std::string &name, std::string &value ) const;
531 
532  //------------------------------------------------------------------------
534  //------------------------------------------------------------------------
535  void Lock()
536  {
537  pMutex.Lock();
538  }
539 
540  //------------------------------------------------------------------------
542  //------------------------------------------------------------------------
543  void UnLock()
544  {
545  pMutex.UnLock();
546  }
547 
548  //------------------------------------------------------------------------
550  //------------------------------------------------------------------------
551  void Tick( time_t now );
552 
553  //------------------------------------------------------------------------
555  //------------------------------------------------------------------------
556  void TimeOutRequests( time_t now );
557 
558  //------------------------------------------------------------------------
560  //------------------------------------------------------------------------
561  void AfterForkChild();
562 
563  //------------------------------------------------------------------------
565  //------------------------------------------------------------------------
566  XRootDStatus TryOtherServer( uint16_t timeout );
567 
568  private:
569  //------------------------------------------------------------------------
570  // Helper for queuing messages
571  //------------------------------------------------------------------------
572  struct RequestData
573  {
574  RequestData(): request(0), handler(0) {}
576  const MessageSendParams &p ):
577  request(r), handler(h), params(p) {}
581  };
582  typedef std::list<RequestData> RequestList;
583 
584  //------------------------------------------------------------------------
591  //------------------------------------------------------------------------
592  template<typename T>
593  Status XAttrOperationImpl( kXR_char subcode,
594  kXR_char options,
595  const std::vector<T> &attrs,
596  ResponseHandler *handler,
597  uint16_t timeout = 0 );
598 
599  //------------------------------------------------------------------------
601  //------------------------------------------------------------------------
602  Status SendOrQueue( const URL &url,
603  Message *msg,
604  ResponseHandler *handler,
605  MessageSendParams &sendParams );
606 
607  //------------------------------------------------------------------------
609  //------------------------------------------------------------------------
610  bool IsRecoverable( const XRootDStatus &stataus ) const;
611 
612  //------------------------------------------------------------------------
618  //------------------------------------------------------------------------
619  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
620 
621  //------------------------------------------------------------------------
623  //------------------------------------------------------------------------
624  Status RunRecovery();
625 
626  //------------------------------------------------------------------------
627  // Send a close and ignore the response
628  //------------------------------------------------------------------------
629  XRootDStatus SendClose( uint16_t timeout );
630 
631  //------------------------------------------------------------------------
633  //------------------------------------------------------------------------
634  bool IsReadOnly() const;
635 
636  //------------------------------------------------------------------------
638  //------------------------------------------------------------------------
639  XRootDStatus ReOpenFileAtServer( const URL &url, uint16_t timeout );
640 
641  //------------------------------------------------------------------------
643  //------------------------------------------------------------------------
644  void FailMessage( RequestData rd, XRootDStatus status );
645 
646  //------------------------------------------------------------------------
648  //------------------------------------------------------------------------
649  void FailQueuedMessages( XRootDStatus status );
650 
651  //------------------------------------------------------------------------
653  //------------------------------------------------------------------------
654  void ReSendQueuedMessages();
655 
656  //------------------------------------------------------------------------
658  //------------------------------------------------------------------------
659  void ReWriteFileHandle( Message *msg );
660 
661  //------------------------------------------------------------------------
663  //------------------------------------------------------------------------
665  {
666  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
667  pRBytes = 0;
668  pVRBytes = 0;
669  pWBytes = 0;
670  pVSegs = 0;
671  pRCount = 0;
672  pVRCount = 0;
673  pWCount = 0;
674  pCloseReason = Status();
675  }
676 
677  //------------------------------------------------------------------------
679  //------------------------------------------------------------------------
680  void MonitorClose( const XRootDStatus *status );
681 
682  //------------------------------------------------------------------------
688  //------------------------------------------------------------------------
689  XRootDStatus IssueRequest( const URL &url,
690  Message *msg,
691  ResponseHandler *handler,
692  MessageSendParams &sendParams );
693 
694  //------------------------------------------------------------------------
696  //------------------------------------------------------------------------
697  XRootDStatus WriteKernelBuffer( uint64_t offset,
698  uint32_t length,
699  std::unique_ptr<XrdSys::KernelBuffer> kbuff,
700  ResponseHandler *handler,
701  uint16_t timeout );
702 
712  uint8_t *pFileHandle;
713  uint16_t pOpenMode;
714  uint16_t pOpenFlags;
716  std::set<Message*> pInTheFly;
717  uint64_t pSessionId;
724 
725  //------------------------------------------------------------------------
726  // Monitoring variables
727  //------------------------------------------------------------------------
728  timeval pOpenTime;
729  uint64_t pRBytes;
730  uint64_t pVRBytes;
731  uint64_t pWBytes;
732  uint64_t pVWBytes;
733  uint64_t pVSegs;
734  uint64_t pRCount;
735  uint64_t pVRCount;
736  uint64_t pWCount;
737  uint64_t pVWCount;
739 
740  //------------------------------------------------------------------------
741  // Holds the OpenHanlder used to issue reopen
742  // (there is only only OpenHandler reopening a file at a time)
743  //------------------------------------------------------------------------
744  ResponseHandlerHolder *pReOpenHandler;
745 
746  //------------------------------------------------------------------------
747  // Responsible for file:// operations on the local filesystem
748  //------------------------------------------------------------------------
750 
751  //------------------------------------------------------------------------
752  // Responsible for Writing/Reading erasure-coded files
753  //------------------------------------------------------------------------
755  };
756 }
757 
758 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:731
unsigned char kXR_char
Definition: XPtypes.hh:65
ListXAttrImpl< false > ListXAttr(Ctx< File > file)
Definition: XrdClFileOperations.hh:1138
CloseImpl< false > Close
Definition: XrdClFileOperations.hh:308
FilePlugIn *& pPlugin
Definition: XrdClFileStateHandler.hh:754
Definition: XrdClAnyObject.hh:32
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:535
SetXAttrImpl< false > SetXAttr(Ctx< File > file, Arg< std::string > name, Arg< std::string > value)
Definition: XrdClFileOperations.hh:798
void UnLock()
Unlock the internal lock.
Definition: XrdClFileStateHandler.hh:543
PgRead flags.
Definition: XrdClFileStateHandler.hh:62
Definition: XrdClMessageUtils.hh:131
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:729
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:970
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:717
VectorReadImpl< false > VectorRead
Definition: XrdClFileOperations.hh:559
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
FcntlImpl< false > Fcntl
Definition: XrdClFileOperations.hh:699
uint64_t pVWBytes
Definition: XrdClFileStateHandler.hh:732
Object stat info.
Definition: XrdClXRootDResponses.hh:399
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:736
RequestData()
Definition: XrdClFileStateHandler.hh:574
The file is closed.
Definition: XrdClFileStateHandler.hh:92
Definition: XrdClOptional.hh:43
Message * request
Definition: XrdClFileStateHandler.hh:578
DelXAttrImpl< false > DelXAttr(Ctx< File > file, Arg< std::string > name)
Definition: XrdClFileOperations.hh:1033
SyncImpl< false > Sync
Definition: XrdClFileOperations.hh:458
uint64_t pVSegs
Definition: XrdClFileStateHandler.hh:733
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:719
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:579
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:916
TruncateImpl< false > Truncate(Ctx< File > file, Arg< uint64_t > size)
Definition: XrdClFileOperations.hh:508
bool pAllowBundledClose
Definition: XrdClFileStateHandler.hh:723
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:664
URL * pWrtRecoveryRedir
Definition: XrdClFileStateHandler.hh:711
Definition: XrdSysPthread.hh:165
bool pDoRecoverRead
Definition: XrdClFileStateHandler.hh:718
LocalFileHandler * pLFileHandler
Definition: XrdClFileStateHandler.hh:749
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:582
Definition: XrdOucIOVec.hh:65
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:716
An interface for file plug-ins.
Definition: XrdClPlugInInterface.hh:38
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:728
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:1035
uint64_t pRCount
Definition: XrdClFileStateHandler.hh:734
MessageSendParams params
Definition: XrdClFileStateHandler.hh:580
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:714
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:721
ResponseHandlerHolder * pReOpenHandler
Definition: XrdClFileStateHandler.hh:744
Definition: XrdClFileStateHandler.hh:572
Recovering from an error.
Definition: XrdClFileStateHandler.hh:95
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:575
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:704
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:738
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:737
Flags
PgRead flags.
Definition: XrdClFileStateHandler.hh:67
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:715
Handle an async response.
Definition: XrdClXRootDResponses.hh:1040
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:707
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:720
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:735
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:705
WriteVImpl< false > WriteV
Definition: XrdClFileOperations.hh:654
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:712
bool pIsChannelEncrypted
Definition: XrdClFileStateHandler.hh:722
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:710
VisaImpl< false > Visa
Definition: XrdClFileOperations.hh:738
URL * pDataServer
Definition: XrdClFileStateHandler.hh:708
uint16_t pOpenMode
Definition: XrdClFileStateHandler.hh:713
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:706
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:730
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:703
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:709
Binary blob representation.
Definition: XrdClBuffer.hh:33