xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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"
34 #include "XrdSys/XrdSysPthread.hh"
35 #include "XrdSys/XrdSysPageSize.hh"
36 
37 #include <list>
38 #include <set>
39 #include <vector>
40 
41 #include <sys/uio.h>
42 #include <stdint.h>
43 
44 namespace
45 {
46  class PgReadHandler;
47  class PgReadRetryHandler;
48  class PgReadSubstitutionHandler;
49 }
50 
51 namespace XrdCl
52 {
53  class ResponseHandlerHolder;
54  class Message;
55 
56  //----------------------------------------------------------------------------
58  //----------------------------------------------------------------------------
59  struct PgReadFlags
60  {
61  //------------------------------------------------------------------------
63  //------------------------------------------------------------------------
64  enum Flags
65  {
66  None = 0, //< Nothing
67  Retry = XrdProto::kXR_pgRetry //< Retry reading currupted page
68 
69  };
70  };
72 
73  //----------------------------------------------------------------------------
75  //----------------------------------------------------------------------------
77  {
78  friend class ::PgReadHandler;
79  friend class ::PgReadRetryHandler;
80  friend class ::PgReadSubstitutionHandler;
81 
82  public:
83  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
87  {
93  CloseInProgress
94  };
95 
96  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  FileStateHandler();
100 
101  //------------------------------------------------------------------------
106  //------------------------------------------------------------------------
107  FileStateHandler( bool useVirtRedirector );
108 
109  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  ~FileStateHandler();
113 
114  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  XRootDStatus Open( const std::string &url,
126  uint16_t flags,
127  uint16_t mode,
128  ResponseHandler *handler,
129  uint16_t timeout = 0 );
130 
131  //------------------------------------------------------------------------
138  //------------------------------------------------------------------------
140  uint16_t timeout = 0 );
141 
142  //------------------------------------------------------------------------
152  //------------------------------------------------------------------------
153  XRootDStatus Stat( bool force,
154  ResponseHandler *handler,
155  uint16_t timeout = 0 );
156 
157 
158  //------------------------------------------------------------------------
173  //------------------------------------------------------------------------
174  XRootDStatus Read( uint64_t offset,
175  uint32_t size,
176  void *buffer,
177  ResponseHandler *handler,
178  uint16_t timeout = 0 );
179 
180  //------------------------------------------------------------------------
193  //------------------------------------------------------------------------
194  XRootDStatus PgRead( uint64_t offset,
195  uint32_t size,
196  void *buffer,
197  ResponseHandler *handler,
198  uint16_t timeout = 0 );
199 
200  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
212  XRootDStatus PgReadRetry( uint64_t offset,
213  uint32_t size,
214  size_t pgnb,
215  void *buffer,
216  PgReadHandler *handler,
217  uint16_t timeout = 0 );
218 
219  //------------------------------------------------------------------------
233  //------------------------------------------------------------------------
234  XRootDStatus PgReadImpl( uint64_t offset,
235  uint32_t size,
236  void *buffer,
237  uint16_t flags,
238  ResponseHandler *handler,
239  uint16_t timeout = 0 );
240 
241  //------------------------------------------------------------------------
251  //------------------------------------------------------------------------
252  XRootDStatus Write( uint64_t offset,
253  uint32_t size,
254  const void *buffer,
255  ResponseHandler *handler,
256  uint16_t timeout = 0 );
257 
258  //------------------------------------------------------------------------
268  //------------------------------------------------------------------------
269  XRootDStatus Write( uint64_t offset,
270  Buffer &&buffer,
271  ResponseHandler *handler,
272  uint16_t timeout = 0 );
273 
274  //------------------------------------------------------------------------
287  //------------------------------------------------------------------------
288  XRootDStatus Write( uint64_t offset,
289  uint32_t size,
290  Optional<uint64_t> fdoff,
291  int fd,
292  ResponseHandler *handler,
293  uint16_t timeout = 0 );
294 
295 
296  //------------------------------------------------------------------------
303  //------------------------------------------------------------------------
305  uint16_t timeout = 0 );
306 
307  //------------------------------------------------------------------------
315  //------------------------------------------------------------------------
316  XRootDStatus Truncate( uint64_t size,
317  ResponseHandler *handler,
318  uint16_t timeout = 0 );
319 
320  //------------------------------------------------------------------------
329  //------------------------------------------------------------------------
330  XRootDStatus VectorRead( const ChunkList &chunks,
331  void *buffer,
332  ResponseHandler *handler,
333  uint16_t timeout = 0 );
334 
335  //------------------------------------------------------------------------
343  //------------------------------------------------------------------------
344  XRootDStatus VectorWrite( const ChunkList &chunks,
345  ResponseHandler *handler,
346  uint16_t timeout = 0 );
347 
348  //------------------------------------------------------------------------
358  //------------------------------------------------------------------------
359  XRootDStatus WriteV( uint64_t offset,
360  const struct iovec *iov,
361  int iovcnt,
362  ResponseHandler *handler,
363  uint16_t timeout = 0 );
364 
365  //------------------------------------------------------------------------
376  //------------------------------------------------------------------------
377  XRootDStatus Fcntl( const Buffer &arg,
378  ResponseHandler *handler,
379  uint16_t timeout = 0 );
380 
381  //------------------------------------------------------------------------
390  //------------------------------------------------------------------------
392  uint16_t timeout = 0 );
393 
394  //------------------------------------------------------------------------
405  //------------------------------------------------------------------------
406  XRootDStatus SetXAttr( const std::vector<xattr_t> &attrs,
407  ResponseHandler *handler,
408  uint16_t timeout = 0 );
409 
410  //------------------------------------------------------------------------
421  //------------------------------------------------------------------------
422  XRootDStatus GetXAttr( const std::vector<std::string> &attrs,
423  ResponseHandler *handler,
424  uint16_t timeout = 0 );
425 
426  //------------------------------------------------------------------------
437  //------------------------------------------------------------------------
438  XRootDStatus DelXAttr( const std::vector<std::string> &attrs,
439  ResponseHandler *handler,
440  uint16_t timeout = 0 );
441 
442  //------------------------------------------------------------------------
452  //------------------------------------------------------------------------
454  uint16_t timeout = 0 );
455 
456  //------------------------------------------------------------------------
458  //------------------------------------------------------------------------
459  void OnOpen( const XRootDStatus *status,
460  const OpenInfo *openInfo,
461  const HostList *hostList );
462 
463  //------------------------------------------------------------------------
465  //------------------------------------------------------------------------
466  void OnClose( const XRootDStatus *status );
467 
468  //------------------------------------------------------------------------
470  //------------------------------------------------------------------------
471  void OnStateError( XRootDStatus *status,
472  Message *message,
473  ResponseHandler *userHandler,
474  MessageSendParams &sendParams );
475 
476  //------------------------------------------------------------------------
478  //------------------------------------------------------------------------
479  void OnStateRedirection( const std::string &redirectUrl,
480  Message *message,
481  ResponseHandler *userHandler,
482  MessageSendParams &sendParams );
483 
484  //------------------------------------------------------------------------
486  //------------------------------------------------------------------------
487  void OnStateResponse( XRootDStatus *status,
488  Message *message,
489  AnyObject *response,
490  HostList *hostList );
491 
492  //------------------------------------------------------------------------
494  //------------------------------------------------------------------------
495  bool IsOpen() const;
496 
497  //------------------------------------------------------------------------
501  //------------------------------------------------------------------------
502  bool SetProperty( const std::string &name, const std::string &value );
503 
504  //------------------------------------------------------------------------
508  //------------------------------------------------------------------------
509  bool GetProperty( const std::string &name, std::string &value ) const;
510 
511  //------------------------------------------------------------------------
513  //------------------------------------------------------------------------
514  void Lock()
515  {
516  pMutex.Lock();
517  }
518 
519  //------------------------------------------------------------------------
521  //------------------------------------------------------------------------
522  void UnLock()
523  {
524  pMutex.UnLock();
525  }
526 
527  //------------------------------------------------------------------------
529  //------------------------------------------------------------------------
530  void Tick( time_t now );
531 
532  //------------------------------------------------------------------------
534  //------------------------------------------------------------------------
535  void TimeOutRequests( time_t now );
536 
537  //------------------------------------------------------------------------
539  //------------------------------------------------------------------------
540  void AfterForkChild();
541 
542  private:
543  //------------------------------------------------------------------------
544  // Helper for queuing messages
545  //------------------------------------------------------------------------
546  struct RequestData
547  {
548  RequestData(): request(0), handler(0) {}
550  const MessageSendParams &p ):
551  request(r), handler(h), params(p) {}
555  };
556  typedef std::list<RequestData> RequestList;
557 
558  //------------------------------------------------------------------------
565  //------------------------------------------------------------------------
566  template<typename T>
567  Status XAttrOperationImpl( kXR_char subcode,
568  kXR_char options,
569  const std::vector<T> &attrs,
570  ResponseHandler *handler,
571  uint16_t timeout = 0 );
572 
573  //------------------------------------------------------------------------
575  //------------------------------------------------------------------------
576  Status SendOrQueue( const URL &url,
577  Message *msg,
578  ResponseHandler *handler,
579  MessageSendParams &sendParams );
580 
581  //------------------------------------------------------------------------
583  //------------------------------------------------------------------------
584  bool IsRecoverable( const XRootDStatus &stataus ) const;
585 
586  //------------------------------------------------------------------------
592  //------------------------------------------------------------------------
593  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
594 
595  //------------------------------------------------------------------------
597  //------------------------------------------------------------------------
598  Status RunRecovery();
599 
600  //------------------------------------------------------------------------
601  // Send a close and ignore the response
602  //------------------------------------------------------------------------
603  XRootDStatus SendClose( uint16_t timeout );
604 
605  //------------------------------------------------------------------------
607  //------------------------------------------------------------------------
608  bool IsReadOnly() const;
609 
610  //------------------------------------------------------------------------
612  //------------------------------------------------------------------------
613  XRootDStatus ReOpenFileAtServer( const URL &url, uint16_t timeout );
614 
615  //------------------------------------------------------------------------
617  //------------------------------------------------------------------------
618  void FailMessage( RequestData rd, XRootDStatus status );
619 
620  //------------------------------------------------------------------------
622  //------------------------------------------------------------------------
623  void FailQueuedMessages( XRootDStatus status );
624 
625  //------------------------------------------------------------------------
627  //------------------------------------------------------------------------
628  void ReSendQueuedMessages();
629 
630  //------------------------------------------------------------------------
632  //------------------------------------------------------------------------
633  void ReWriteFileHandle( Message *msg );
634 
635  //------------------------------------------------------------------------
637  //------------------------------------------------------------------------
639  {
640  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
641  pRBytes = 0;
642  pVRBytes = 0;
643  pWBytes = 0;
644  pVSegs = 0;
645  pRCount = 0;
646  pVRCount = 0;
647  pWCount = 0;
648  pCloseReason = Status();
649  }
650 
651  //------------------------------------------------------------------------
653  //------------------------------------------------------------------------
654  void MonitorClose( const XRootDStatus *status );
655 
656  //------------------------------------------------------------------------
662  //------------------------------------------------------------------------
663  XRootDStatus IssueRequest( const URL &url,
664  Message *msg,
665  ResponseHandler *handler,
666  MessageSendParams &sendParams );
667 
668  //------------------------------------------------------------------------
670  //------------------------------------------------------------------------
671  XRootDStatus WriteKernelBuffer( uint64_t offset,
672  uint32_t length,
673  std::unique_ptr<XrdSys::KernelBuffer> kbuff,
674  ResponseHandler *handler,
675  uint16_t timeout );
676 
686  uint8_t *pFileHandle;
687  uint16_t pOpenMode;
688  uint16_t pOpenFlags;
689  RequestList pToBeRecovered;
690  std::set<Message*> pInTheFly;
691  uint64_t pSessionId;
698 
699  //------------------------------------------------------------------------
700  // Monitoring variables
701  //------------------------------------------------------------------------
702  timeval pOpenTime;
703  uint64_t pRBytes;
704  uint64_t pVRBytes;
705  uint64_t pWBytes;
706  uint64_t pVWBytes;
707  uint64_t pVSegs;
708  uint64_t pRCount;
709  uint64_t pVRCount;
710  uint64_t pWCount;
711  uint64_t pVWCount;
713 
714  //------------------------------------------------------------------------
715  // Holds the OpenHanlder used to issue reopen
716  // (there is only only OpenHandler reopening a file at a time)
717  //------------------------------------------------------------------------
718  ResponseHandlerHolder *pReOpenHandler;
719 
720  //------------------------------------------------------------------------
721  // Responsible for file:// operations on the local filesystem
722  //------------------------------------------------------------------------
724  };
725 }
726 
727 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:705
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
Definition: XrdClAnyObject.hh:32
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:514
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:522
PgRead flags.
Definition: XrdClFileStateHandler.hh:59
Definition: XrdClMessageUtils.hh:131
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:703
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:966
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:691
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:706
Object stat info.
Definition: XrdClXRootDResponses.hh:395
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:710
RequestData()
Definition: XrdClFileStateHandler.hh:548
The file is closed.
Definition: XrdClFileStateHandler.hh:88
Definition: XrdClOptional.hh:43
Message * request
Definition: XrdClFileStateHandler.hh:552
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:707
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
bool pDoRecoverWrite
Definition: XrdClFileStateHandler.hh:693
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:553
Procedure execution status.
Definition: XrdClStatus.hh:110
static const int kXR_pgRetry
Definition: XProtocol.hh:482
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:697
Opening is in progress.
Definition: XrdClFileStateHandler.hh:92
VectorWriteImpl< false > VectorWrite
Definition: XrdClFileOperations.hh:605
Information returned by file open operation.
Definition: XrdClXRootDResponses.hh:848
void ResetMonitoringVars()
Reset monitoring vars.
Definition: XrdClFileStateHandler.hh:638
URL * pWrtRecoveryRedir
Definition: XrdClFileStateHandler.hh:685
Definition: XrdSysPthread.hh:165
bool pDoRecoverRead
Definition: XrdClFileStateHandler.hh:692
LocalFileHandler * pLFileHandler
Definition: XrdClFileStateHandler.hh:723
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:556
Definition: XrdOucIOVec.hh:65
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:690
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
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:702
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:1031
uint64_t pRCount
Definition: XrdClFileStateHandler.hh:708
MessageSendParams params
Definition: XrdClFileStateHandler.hh:554
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:688
Opening has failed.
Definition: XrdClFileStateHandler.hh:90
Opening has succeeded.
Definition: XrdClFileStateHandler.hh:89
none object for initializing empty Optional
Definition: XrdClOptional.hh:35
Request status.
Definition: XrdClXRootDResponses.hh:214
Definition: XrdClFileStateHandler.hh:67
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:86
bool pUseVirtRedirector
Definition: XrdClFileStateHandler.hh:695
ResponseHandlerHolder * pReOpenHandler
Definition: XrdClFileStateHandler.hh:718
Definition: XrdClFileStateHandler.hh:546
Recovering from an error.
Definition: XrdClFileStateHandler.hh:91
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:549
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:678
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:712
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:711
Flags
PgRead flags.
Definition: XrdClFileStateHandler.hh:64
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:689
Handle an async response.
Definition: XrdClXRootDResponses.hh:1036
Handle the stateful operations.
Definition: XrdClFileStateHandler.hh:76
Definition: XrdClLocalFileHandler.hh:32
OpenImpl< false > Open
Definition: XrdClFileOperations.hh:211
URL representation.
Definition: XrdClURL.hh:30
URL * pFileUrl
Definition: XrdClFileStateHandler.hh:681
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:694
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:709
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:679
WriteVImpl< false > WriteV
Definition: XrdClFileOperations.hh:654
#define XRDOUC_ENUM_OPERATORS(T)
Definition: XrdOucEnum.hh:22
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:686
bool pIsChannelEncrypted
Definition: XrdClFileStateHandler.hh:696
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:684
VisaImpl< false > Visa
Definition: XrdClFileOperations.hh:738
URL * pDataServer
Definition: XrdClFileStateHandler.hh:682
uint16_t pOpenMode
Definition: XrdClFileStateHandler.hh:687
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:680
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:704
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:677
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:683
Binary blob representation.
Definition: XrdClBuffer.hh:33