XRootD
Loading...
Searching...
No Matches
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
37
38#include <list>
39#include <set>
40#include <vector>
41
42#include <sys/time.h>
43#include <sys/uio.h>
44#include <cstdint>
45
46namespace
47{
48 class PgReadHandler;
49 class PgReadRetryHandler;
50 class PgReadSubstitutionHandler;
51 class OpenHandler;
52}
53
54namespace XrdCl
55{
56 class Message;
57 class EcHandler;
58
59 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
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 //------------------------------------------------------------------------
117
118 //------------------------------------------------------------------------
128 //------------------------------------------------------------------------
129 static XRootDStatus Open( std::shared_ptr<FileStateHandler> &self,
130 const std::string &url,
131 uint16_t flags,
132 uint16_t mode,
133 ResponseHandler *handler,
134 uint16_t timeout = 0 );
135
136 //------------------------------------------------------------------------
143 //------------------------------------------------------------------------
144 static XRootDStatus Close( std::shared_ptr<FileStateHandler> &self,
145 ResponseHandler *handler,
146 uint16_t timeout = 0 );
147
148 //------------------------------------------------------------------------
158 //------------------------------------------------------------------------
159 static XRootDStatus Stat( std::shared_ptr<FileStateHandler> &self,
160 bool force,
161 ResponseHandler *handler,
162 uint16_t timeout = 0 );
163
164
165 //------------------------------------------------------------------------
180 //------------------------------------------------------------------------
181 static XRootDStatus Read( std::shared_ptr<FileStateHandler> &self,
182 uint64_t offset,
183 uint32_t size,
184 void *buffer,
185 ResponseHandler *handler,
186 uint16_t timeout = 0 );
187
188 //------------------------------------------------------------------------
201 //------------------------------------------------------------------------
202 static XRootDStatus PgRead( std::shared_ptr<FileStateHandler> &self,
203 uint64_t offset,
204 uint32_t size,
205 void *buffer,
206 ResponseHandler *handler,
207 uint16_t timeout = 0 );
208
209 //------------------------------------------------------------------------
220 //------------------------------------------------------------------------
221 static XRootDStatus PgReadRetry( std::shared_ptr<FileStateHandler> &self,
222 uint64_t offset,
223 uint32_t size,
224 size_t pgnb,
225 void *buffer,
226 PgReadHandler *handler,
227 uint16_t timeout = 0 );
228
229 //------------------------------------------------------------------------
243 //------------------------------------------------------------------------
244 static XRootDStatus PgReadImpl( std::shared_ptr<FileStateHandler> &self,
245 uint64_t offset,
246 uint32_t size,
247 void *buffer,
248 uint16_t flags,
249 ResponseHandler *handler,
250 uint16_t timeout = 0 );
251
252 //------------------------------------------------------------------------
262 //------------------------------------------------------------------------
263 static XRootDStatus Write( std::shared_ptr<FileStateHandler> &self,
264 uint64_t offset,
265 uint32_t size,
266 const void *buffer,
267 ResponseHandler *handler,
268 uint16_t timeout = 0 );
269
270 //------------------------------------------------------------------------
280 //------------------------------------------------------------------------
281 static XRootDStatus Write( std::shared_ptr<FileStateHandler> &self,
282 uint64_t offset,
283 Buffer &&buffer,
284 ResponseHandler *handler,
285 uint16_t timeout = 0 );
286
287 //------------------------------------------------------------------------
300 //------------------------------------------------------------------------
301 static XRootDStatus Write( std::shared_ptr<FileStateHandler> &self,
302 uint64_t offset,
303 uint32_t size,
304 Optional<uint64_t> fdoff,
305 int fd,
306 ResponseHandler *handler,
307 uint16_t timeout = 0 );
308
309 //------------------------------------------------------------------------
320 //------------------------------------------------------------------------
321 static XRootDStatus PgWrite( std::shared_ptr<FileStateHandler> &self,
322 uint64_t offset,
323 uint32_t size,
324 const void *buffer,
325 std::vector<uint32_t> &cksums,
326 ResponseHandler *handler,
327 uint16_t timeout = 0 );
328
329 //------------------------------------------------------------------------
339 //------------------------------------------------------------------------
340 static XRootDStatus PgWriteRetry( std::shared_ptr<FileStateHandler> &self,
341 uint64_t offset,
342 uint32_t size,
343 const void *buffer,
344 uint32_t digest,
345 ResponseHandler *handler,
346 uint16_t timeout = 0 );
347
348 //------------------------------------------------------------------------
360 //------------------------------------------------------------------------
361 static XRootDStatus PgWriteImpl( std::shared_ptr<FileStateHandler> &self,
362 uint64_t offset,
363 uint32_t size,
364 const void *buffer,
365 std::vector<uint32_t> &cksums,
366 kXR_char flags,
367 ResponseHandler *handler,
368 uint16_t timeout = 0 );
369
370 //------------------------------------------------------------------------
377 //------------------------------------------------------------------------
378 static XRootDStatus Sync( std::shared_ptr<FileStateHandler> &self,
379 ResponseHandler *handler,
380 uint16_t timeout = 0 );
381
382 //------------------------------------------------------------------------
390 //------------------------------------------------------------------------
391 static XRootDStatus Truncate( std::shared_ptr<FileStateHandler> &self,
392 uint64_t size,
393 ResponseHandler *handler,
394 uint16_t timeout = 0 );
395
396 //------------------------------------------------------------------------
405 //------------------------------------------------------------------------
406 static XRootDStatus VectorRead( std::shared_ptr<FileStateHandler> &self,
407 const ChunkList &chunks,
408 void *buffer,
409 ResponseHandler *handler,
410 uint16_t timeout = 0 );
411
412 //------------------------------------------------------------------------
420 //------------------------------------------------------------------------
421 static XRootDStatus VectorWrite( std::shared_ptr<FileStateHandler> &self,
422 const ChunkList &chunks,
423 ResponseHandler *handler,
424 uint16_t timeout = 0 );
425
426 //------------------------------------------------------------------------
436 //------------------------------------------------------------------------
437 static XRootDStatus WriteV( std::shared_ptr<FileStateHandler> &self,
438 uint64_t offset,
439 const struct iovec *iov,
440 int iovcnt,
441 ResponseHandler *handler,
442 uint16_t timeout = 0 );
443
444 //------------------------------------------------------------------------
454 //------------------------------------------------------------------------
455 static XRootDStatus ReadV( std::shared_ptr<FileStateHandler> &self,
456 uint64_t offset,
457 struct iovec *iov,
458 int iovcnt,
459 ResponseHandler *handler,
460 uint16_t timeout = 0 );
461
462 //------------------------------------------------------------------------
473 //------------------------------------------------------------------------
474 static XRootDStatus Fcntl( std::shared_ptr<FileStateHandler> &self,
475 const Buffer &arg,
476 ResponseHandler *handler,
477 uint16_t timeout = 0 );
478
479 //------------------------------------------------------------------------
488 //------------------------------------------------------------------------
489 static XRootDStatus Visa( std::shared_ptr<FileStateHandler> &self,
490 ResponseHandler *handler,
491 uint16_t timeout = 0 );
492
493 //------------------------------------------------------------------------
504 //------------------------------------------------------------------------
505 static XRootDStatus SetXAttr( std::shared_ptr<FileStateHandler> &self,
506 const std::vector<xattr_t> &attrs,
507 ResponseHandler *handler,
508 uint16_t timeout = 0 );
509
510 //------------------------------------------------------------------------
521 //------------------------------------------------------------------------
522 static XRootDStatus GetXAttr( std::shared_ptr<FileStateHandler> &self,
523 const std::vector<std::string> &attrs,
524 ResponseHandler *handler,
525 uint16_t timeout = 0 );
526
527 //------------------------------------------------------------------------
538 //------------------------------------------------------------------------
539 static XRootDStatus DelXAttr( std::shared_ptr<FileStateHandler> &self,
540 const std::vector<std::string> &attrs,
541 ResponseHandler *handler,
542 uint16_t timeout = 0 );
543
544 //------------------------------------------------------------------------
554 //------------------------------------------------------------------------
555 static XRootDStatus ListXAttr( std::shared_ptr<FileStateHandler> &self,
556 ResponseHandler *handler,
557 uint16_t timeout = 0 );
558
559 //------------------------------------------------------------------------
569 //------------------------------------------------------------------------
570 static XRootDStatus Checkpoint( std::shared_ptr<FileStateHandler> &self,
571 kXR_char code,
572 ResponseHandler *handler,
573 uint16_t timeout = 0 );
574
575 //------------------------------------------------------------------------
585 //------------------------------------------------------------------------
586 static XRootDStatus ChkptWrt( std::shared_ptr<FileStateHandler> &self,
587 uint64_t offset,
588 uint32_t size,
589 const void *buffer,
590 ResponseHandler *handler,
591 uint16_t timeout = 0 );
592
593 //------------------------------------------------------------------------
603 //------------------------------------------------------------------------
604 static XRootDStatus ChkptWrtV( std::shared_ptr<FileStateHandler> &self,
605 uint64_t offset,
606 const struct iovec *iov,
607 int iovcnt,
608 ResponseHandler *handler,
609 uint16_t timeout = 0 );
610
611 //------------------------------------------------------------------------
613 //------------------------------------------------------------------------
614 void OnOpen( const XRootDStatus *status,
615 const OpenInfo *openInfo,
616 const HostList *hostList );
617
618 //------------------------------------------------------------------------
620 //------------------------------------------------------------------------
621 void OnClose( const XRootDStatus *status );
622
623 //------------------------------------------------------------------------
625 //------------------------------------------------------------------------
626 static void OnStateError( std::shared_ptr<FileStateHandler> &self,
627 XRootDStatus *status,
628 Message *message,
629 ResponseHandler *userHandler,
630 MessageSendParams &sendParams );
631
632 //------------------------------------------------------------------------
634 //------------------------------------------------------------------------
635 static void OnStateRedirection( std::shared_ptr<FileStateHandler> &self,
636 const std::string &redirectUrl,
637 Message *message,
638 ResponseHandler *userHandler,
639 MessageSendParams &sendParams );
640
641 //------------------------------------------------------------------------
643 //------------------------------------------------------------------------
644 static void OnStateResponse( std::shared_ptr<FileStateHandler> &self,
645 XRootDStatus *status,
646 Message *message,
647 AnyObject *response,
648 HostList *hostList );
649
650 //------------------------------------------------------------------------
652 //------------------------------------------------------------------------
653 bool IsOpen() const;
654
655 //------------------------------------------------------------------------
657 //------------------------------------------------------------------------
658 inline bool IsSecure() const
659 {
660 return pIsChannelEncrypted;
661 }
662
663 //------------------------------------------------------------------------
667 //------------------------------------------------------------------------
668 bool SetProperty( const std::string &name, const std::string &value );
669
670 //------------------------------------------------------------------------
674 //------------------------------------------------------------------------
675 bool GetProperty( const std::string &name, std::string &value ) const;
676
677 //------------------------------------------------------------------------
679 //------------------------------------------------------------------------
680 void Lock()
681 {
682 pMutex.Lock();
683 }
684
685 //------------------------------------------------------------------------
687 //------------------------------------------------------------------------
688 void UnLock()
689 {
690 pMutex.UnLock();
691 }
692
693 //------------------------------------------------------------------------
695 //------------------------------------------------------------------------
696 void Tick( time_t now );
697
698 //------------------------------------------------------------------------
700 //------------------------------------------------------------------------
701 void TimeOutRequests( time_t now );
702
703 //------------------------------------------------------------------------
705 //------------------------------------------------------------------------
706 void AfterForkChild();
707
708 //------------------------------------------------------------------------
710 //------------------------------------------------------------------------
711 static XRootDStatus TryOtherServer( std::shared_ptr<FileStateHandler> &self,
712 uint16_t timeout );
713
714 private:
715 //------------------------------------------------------------------------
716 // Helper for queuing messages
717 //------------------------------------------------------------------------
718 struct RequestData
719 {
720 RequestData(): request(0), handler(0) {}
721 RequestData( Message *r, ResponseHandler *h,
722 const MessageSendParams &p ):
723 request(r), handler(h), params(p) {}
724 Message *request;
725 ResponseHandler *handler;
726 MessageSendParams params;
727 };
728 typedef std::list<RequestData> RequestList;
729
730 //------------------------------------------------------------------------
737 //------------------------------------------------------------------------
738 template<typename T>
739 static Status XAttrOperationImpl( std::shared_ptr<FileStateHandler> &self,
740 kXR_char subcode,
741 kXR_char options,
742 const std::vector<T> &attrs,
743 ResponseHandler *handler,
744 uint16_t timeout = 0 );
745
746 //------------------------------------------------------------------------
748 //------------------------------------------------------------------------
749 static Status SendOrQueue( std::shared_ptr<FileStateHandler> &self,
750 const URL &url,
751 Message *msg,
752 ResponseHandler *handler,
753 MessageSendParams &sendParams );
754
755 //------------------------------------------------------------------------
757 //------------------------------------------------------------------------
758 bool IsRecoverable( const XRootDStatus &stataus ) const;
759
760 //------------------------------------------------------------------------
766 //------------------------------------------------------------------------
767 static Status RecoverMessage( std::shared_ptr<FileStateHandler> &self,
768 RequestData rd,
769 bool callbackOnFailure = true );
770
771 //------------------------------------------------------------------------
773 //------------------------------------------------------------------------
774 static Status RunRecovery( std::shared_ptr<FileStateHandler> &self );
775
776 //------------------------------------------------------------------------
777 // Send a close and ignore the response
778 //------------------------------------------------------------------------
779 static XRootDStatus SendClose( std::shared_ptr<FileStateHandler> &self,
780 uint16_t timeout );
781
782 //------------------------------------------------------------------------
784 //------------------------------------------------------------------------
785 bool IsReadOnly() const;
786
787 //------------------------------------------------------------------------
789 //------------------------------------------------------------------------
790 static XRootDStatus ReOpenFileAtServer( std::shared_ptr<FileStateHandler> &self,
791 const URL &url,
792 uint16_t timeout );
793
794 //------------------------------------------------------------------------
796 //------------------------------------------------------------------------
797 void FailMessage( RequestData rd, XRootDStatus status );
798
799 //------------------------------------------------------------------------
801 //------------------------------------------------------------------------
802 void FailQueuedMessages( XRootDStatus status );
803
804 //------------------------------------------------------------------------
806 //------------------------------------------------------------------------
807 void ReSendQueuedMessages();
808
809 //------------------------------------------------------------------------
811 //------------------------------------------------------------------------
812 void ReWriteFileHandle( Message *msg );
813
814 //------------------------------------------------------------------------
816 //------------------------------------------------------------------------
817 void ResetMonitoringVars()
818 {
819 pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
820 pRBytes = 0;
821 pVRBytes = 0;
822 pWBytes = 0;
823 pVSegs = 0;
824 pRCount = 0;
825 pVRCount = 0;
826 pWCount = 0;
827 pCloseReason = Status();
828 }
829
830 //------------------------------------------------------------------------
832 //------------------------------------------------------------------------
833 void MonitorClose( const XRootDStatus *status );
834
835 //------------------------------------------------------------------------
841 //------------------------------------------------------------------------
842 XRootDStatus IssueRequest( const URL &url,
843 Message *msg,
844 ResponseHandler *handler,
845 MessageSendParams &sendParams );
846
847 //------------------------------------------------------------------------
849 //------------------------------------------------------------------------
850 static XRootDStatus WriteKernelBuffer( std::shared_ptr<FileStateHandler> &self,
851 uint64_t offset,
852 uint32_t length,
853 std::unique_ptr<XrdSys::KernelBuffer> kbuff,
854 ResponseHandler *handler,
855 uint16_t timeout );
856
857 mutable XrdSysMutex pMutex;
858 FileStatus pFileState;
859 XRootDStatus pStatus;
860 StatInfo *pStatInfo;
861 URL *pFileUrl;
862 URL *pDataServer;
863 URL *pLoadBalancer;
864 URL *pStateRedirect;
865 URL *pWrtRecoveryRedir;
866 uint8_t *pFileHandle;
867 uint16_t pOpenMode;
868 uint16_t pOpenFlags;
869 RequestList pToBeRecovered;
870 std::set<Message*> pInTheFly;
871 uint64_t pSessionId;
872 bool pDoRecoverRead;
873 bool pDoRecoverWrite;
874 bool pFollowRedirects;
875 bool pUseVirtRedirector;
876 bool pIsChannelEncrypted;
877 bool pAllowBundledClose;
878
879 //------------------------------------------------------------------------
880 // Monitoring variables
881 //------------------------------------------------------------------------
882 timeval pOpenTime;
883 uint64_t pRBytes;
884 uint64_t pVRBytes;
885 uint64_t pWBytes;
886 uint64_t pVWBytes;
887 uint64_t pVSegs;
888 uint64_t pRCount;
889 uint64_t pVRCount;
890 uint64_t pWCount;
891 uint64_t pVWCount;
892 XRootDStatus pCloseReason;
893
894 //------------------------------------------------------------------------
895 // Responsible for file:// operations on the local filesystem
896 //------------------------------------------------------------------------
897 LocalFileHandler *pLFileHandler;
898
899 //------------------------------------------------------------------------
900 // Responsible for Writing/Reading erasure-coded files
901 //------------------------------------------------------------------------
902 FilePlugIn *&pPlugin;
903 };
904}
905
906#endif // __XRD_CL_FILE_STATE_HANDLER_HH__
unsigned char kXR_char
Definition XPtypes.hh:65
struct stat Stat
Definition XrdCks.cc:49
#define XRDOUC_ENUM_OPERATORS(T)
Definition XrdOucEnum.hh:22
Binary blob representation.
An interface for file plug-ins.
Handle the stateful operations.
@ OpenInProgress
Opening is in progress.
@ Opened
Opening has succeeded.
@ Recovering
Recovering from an error.
void UnLock()
Unlock the internal lock.
bool IsSecure() const
Check if the file is using an encrypted connection.
void Lock()
Lock the internal lock.
The message representation used throughout the system.
Information returned by file open operation.
PgRead operation (.
PgWrite operation (.
Handle an async response.
VectorWriteImpl< false > VectorWrite(Ctx< File > file, Arg< ChunkList > chunks, uint16_t timeout=0)
Factory for creating VectorWriteImpl objects.
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.
GetXAttrImpl< false > GetXAttr(Ctx< File > file, Arg< std::string > name)
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.
CheckpointImpl< false > Checkpoint(Ctx< File > file, Arg< ChkPtCode > code, uint16_t timeout=0)
Factory for creating ReadImpl objects.
SyncImpl< false > Sync(Ctx< File > file, uint16_t timeout=0)
Factory for creating SyncImpl objects.
CloseImpl< false > Close(Ctx< File > file, uint16_t timeout=0)
Factory for creating CloseImpl objects.
std::vector< HostInfo > HostList
DelXAttrImpl< false > DelXAttr(Ctx< File > file, Arg< std::string > name)
TruncateImpl< false > Truncate(Ctx< File > file, Arg< uint64_t > size, uint16_t timeout)
FcntlImpl< false > Fcntl
PgReadImpl< false > PgRead(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating PgReadImpl objects.
WriteVImpl< false > WriteV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec > > iov, uint16_t timeout=0)
Factory for creating WriteVImpl objects.
VisaImpl< false > Visa
SetXAttrImpl< false > SetXAttr(Ctx< File > file, Arg< std::string > name, Arg< std::string > value)
ListXAttrImpl< false > ListXAttr(Ctx< File > file)
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.
PgWriteImpl< false > PgWrite(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, Arg< std::vector< uint32_t > > cksums, uint16_t timeout=0)
Factory for creating PgReadImpl objects.
std::vector< ChunkInfo > ChunkList
List of chunks.
VectorReadImpl< false > VectorRead(Ctx< File > file, Arg< ChunkList > chunks, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating VectorReadImpl objects.
OpenImpl< false > Open(Ctx< File > file, Arg< std::string > url, Arg< OpenFlags::Flags > flags, Arg< Access::Mode > mode=Access::None, uint16_t timeout=0)
Factory for creating ReadImpl objects.
ChkptWrtVImpl< false > ChkptWrtV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec > > iov, uint16_t timeout=0)
Factory for creating ChkptWrtVImpl objects.
none object for initializing empty Optional
static const int kXR_pgRetry
Definition XProtocol.hh:503