XRootD
XrdXrootdAioTask.hh
Go to the documentation of this file.
1 #ifndef __XRDXROOTDAIOTASK_H__
2 #define __XRDXROOTDAIOTASK_H__
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d A i o T a s k . h h */
6 /* */
7 /* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include "Xrd/XrdJob.hh"
35 #include "XrdSys/XrdSysPthread.hh"
36 #include "XrdSys/XrdSysRAtomic.hh"
37 
38 using namespace XrdSys;
39 
40 class XrdLink;
41 class XrdXrootdAioBuff;
42 class XrdXrootdNormAio;
43 class XrdXrootdPgrwAio;
44 class XrdXrootdFile;
45 
47 {
48 public:
49 friend class XrdXrootdAioFob;
50 
51  void Completed(XrdXrootdAioBuff *aioP);
52 
53  const char *ID();
54 
55  void Init(XrdXrootdProtocol *protP,
56  XrdXrootdResponse &resp,
57  XrdXrootdFile *fP);
58 
59 virtual void Read(long long offs, int dlen) = 0;
60 
61 virtual void Recycle(bool release) = 0;
62 
64 
65 virtual int Write(long long offs, int dlen) = 0;
66 
67 protected:
68 
69  XrdXrootdAioTask(const char *what="aio request")
70  : XrdJob(what), aioReady(aioMutex) {}
71 virtual ~XrdXrootdAioTask() {}
72 
73 virtual void CopyF2L() = 0;
74 virtual int CopyL2F() = 0;
75 virtual bool CopyL2F(XrdXrootdAioBuff *aioP) = 0;
76  bool Drain();
77  int gdDone() override;
78  void gdFail() override;
79  XrdXrootdAioBuff* getBuff(bool wait);
80  void SendError(int rc, const char *eText);
81  void SendFSError(int rc);
82  bool Validate(XrdXrootdAioBuff* aioP);
83 
84 static const char* TraceID;
85 
86  XrdSysMutex aioMutex; // Locks private data
89  XrdXrootdAioBuff* pendQEnd; // -> Last element in pendQ
90 
91 union {XrdXrootdNormAio* nextNorm; // Never used in conflicting context!
92  XrdXrootdPgrwAio* nextPgrw;
93  XrdXrootdAioTask* nextTask;
94  };
95 
96  XrdXrootdProtocol* Protocol; // -> Protocol associated with dataLink
97  XrdLink* dataLink; // -> Network link
98  XrdXrootdFile* dataFile; // -> Associated file
99 union {XrdXrootdAioBuff *finalRead; // -> A short read indicating EOF
100  XrdXrootdAioBuff *pendWrite; // -> Pending write operation
101  };
102  off_t highOffset; // F2L: EOF offset L2F: initial offset
103  off_t dataOffset; // Next offset
104  int dataLen; // Size remaining
105 
106  char aioState; // See aioXXX below
108  RAtomic_bool isDone; // Request finished
109  char Status; // Offline | Running | Waiting
110 
112 
113 // These values may be present in aioState
114 //
115 static const int aioDead = 0x01; // This aio encountered a fatal link error
116 static const int aioHeld = 0x02; // This aio is recycled but held
117 static const int aioPage = 0x04; // This read is a pgread
118 static const int aioRead = 0x08; // This is a read (i.e. File to Link copy)
119 static const int aioSchd = 0x10; // Next read has been scheduled
120 
121 // These must be inspected or set with aioMutex held
122 //
123 static const int Offline = 0; // Needs to be rescheduled (read only)
124 static const int Running = 1; // Executing
125 static const int Waiting = 2; // Waiting for buffer needs to be signaled
126 
127 private:
128 
129  bool Wait4Buff(int maxWait=0);
130 };
131 #endif
#define ID
Definition: XrdJob.hh:43
virtual void Read(long long offs, int dlen)=0
XrdSysCondVar2 aioReady
virtual void Recycle(bool release)=0
virtual int CopyL2F()=0
XrdXrootdFile * dataFile
virtual ~XrdXrootdAioTask()
XrdSysMutex aioMutex
virtual int Write(long long offs, int dlen)=0
XrdXrootdProtocol * urProtocol()
XrdXrootdAioBuff * pendQ
XrdXrootdResponse Response
virtual bool CopyL2F(XrdXrootdAioBuff *aioP)=0
XrdXrootdAioBuff * pendQEnd
virtual void CopyF2L()=0
XrdXrootdAioTask(const char *what="aio request")
static const char * TraceID
RAtomic_uchar inFlight
XrdXrootdProtocol * Protocol
ProtocolImpl< false > Protocol