xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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!
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
ProtocolImpl< false > Protocol
Definition: XrdClFileSystemOperations.hh:698
XrdXrootdPgrwAio * nextPgrw
Definition: XrdXrootdAioTask.hh:92
XrdXrootdProtocol * Protocol
Definition: XrdXrootdAioTask.hh:96
int dataLen
Definition: XrdXrootdAioTask.hh:104
RAtomic_uchar inFlight
Definition: XrdXrootdAioTask.hh:107
Definition: XrdXrootdAioBuff.hh:40
ssize_t Read(int fd, KernelBuffer &buffer, uint32_t length, int64_t offset)
Definition: XrdSysKernelBuffer.hh:410
virtual ~XrdXrootdAioTask()
Definition: XrdXrootdAioTask.hh:71
XrdLink * dataLink
Definition: XrdXrootdAioTask.hh:97
XrdXrootdResponse Response
Definition: XrdXrootdAioTask.hh:111
off_t highOffset
Definition: XrdXrootdAioTask.hh:102
Definition: XrdXrootdProtocol.hh:154
Definition: XrdXrootdFile.hh:100
Definition: XrdSysPthread.hh:164
XrdSysMutex aioMutex
Definition: XrdXrootdAioTask.hh:86
XrdXrootdNormAio * nextNorm
Definition: XrdXrootdAioTask.hh:91
Definition: XrdXrootdPgrwAio.hh:38
XrdXrootdFile * dataFile
Definition: XrdXrootdAioTask.hh:98
XrdXrootdAioBuff * pendWrite
Definition: XrdXrootdAioTask.hh:100
XrdXrootdAioTask(const char *what="aio request")
Definition: XrdXrootdAioTask.hh:69
Definition: XrdSysPthread.hh:299
RAtomic_bool isDone
Definition: XrdXrootdAioTask.hh:108
XrdXrootdAioBuff * finalRead
Definition: XrdXrootdAioTask.hh:99
Definition: XrdXrootdAioTask.hh:46
Definition: XrdSysRAtomic.hh:254
XrdXrootdAioBuff * pendQ
Definition: XrdXrootdAioTask.hh:88
Definition: XrdXrootdResponse.hh:48
char aioState
Definition: XrdXrootdAioTask.hh:106
Definition: XrdXrootdNormAio.hh:38
ssize_t Write(int fd, KernelBuffer &buffer, int64_t offset)
Definition: XrdSysKernelBuffer.hh:432
char Status
Definition: XrdXrootdAioTask.hh:109
Definition: XrdXrootdAioFob.hh:37
XrdXrootdAioTask * nextTask
Definition: XrdXrootdAioTask.hh:93
static const char * TraceID
Definition: XrdXrootdAioTask.hh:84
gdCallBack()
Definition: XrdXrootdProtocol.hh:124
XrdSysCondVar2 aioReady
Definition: XrdXrootdAioTask.hh:87
XrdXrootdProtocol * urProtocol()
Definition: XrdXrootdAioTask.hh:63
Definition: XrdJob.hh:42
off_t dataOffset
Definition: XrdXrootdAioTask.hh:103
XrdXrootdAioBuff * pendQEnd
Definition: XrdXrootdAioTask.hh:89