00001 #ifndef __XRDXROOTDAIO__ 00002 #define __XRDXROOTDAIO__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d X r o o t d A i o . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id: XrdXrootdAio.hh 22437 2008-03-04 14:35:16Z rdm $ 00014 00015 #include "XProtocol/XPtypes.hh" 00016 #include "XrdSys/XrdSysPthread.hh" 00017 #include "XrdSfs/XrdSfsAio.hh" 00018 #include "Xrd/XrdScheduler.hh" 00019 #include "XrdXrootd/XrdXrootdResponse.hh" 00020 00021 /******************************************************************************/ 00022 /* X r d X r o o t d A i o */ 00023 /******************************************************************************/ 00024 00025 // The XrdXrootdAio object represents a single aio read or write operation. One 00026 // or more of these are allocated to the XrdXrootdAioReq and passed as upcast 00027 // arguments to the sfs file object to effect asynchronous I/O. 00028 00029 class XrdBuffer; 00030 class XrdBuffManager; 00031 class XrdSysError; 00032 class XrdXrootdAioReq; 00033 class XrdXrootdStats; 00034 00035 class XrdXrootdAio : public XrdSfsAio 00036 { 00037 friend class XrdXrootdAioReq; 00038 public: 00039 XrdBuffer *buffp; // -> Buffer object 00040 00041 virtual void doneRead(); 00042 00043 virtual void doneWrite(); 00044 00045 virtual void Recycle(); 00046 00047 00048 XrdXrootdAio() {Next=0; aioReq=0; buffp=0;} 00049 ~XrdXrootdAio() {}; 00050 00051 private: 00052 00053 static XrdXrootdAio *Alloc(XrdXrootdAioReq *arp, int bsize=0); 00054 static XrdXrootdAio *addBlock(); 00055 00056 static const char *TraceID; 00057 static XrdBuffManager *BPool; // -> Buffer Manager 00058 static XrdScheduler *Sched; // -> System Scheduler 00059 static XrdXrootdStats *SI; // -> System Statistics 00060 static XrdSysMutex fqMutex; // Locks static data 00061 static XrdXrootdAio *fqFirst; // -> Object in free queue 00062 static int maxAio; // Maximum Aio objects we can yet have 00063 00064 XrdXrootdAio *Next; // Chain pointer 00065 XrdXrootdAioReq *aioReq; // -> Associated request object 00066 }; 00067 00068 /******************************************************************************/ 00069 /* X r d X r o o t d A i o R e q */ 00070 /******************************************************************************/ 00071 00072 // The XrdXrootdAioReq object represents a complete aio request. It handles 00073 // the appropriate translation of the synchrnous request to an async one, 00074 // provides the redrive logic, and handles ending status. 00075 // 00076 class XrdLink; 00077 class XrdXrootdFile; 00078 class XrdXrootdProtocol; 00079 00080 class XrdXrootdAioReq : public XrdJob 00081 { 00082 friend class XrdXrootdAio; 00083 public: 00084 00085 static XrdXrootdAioReq *Alloc(XrdXrootdProtocol *p, char iot, int numaio=0); 00086 00087 void DoIt() {if (aioType == 'r') endRead(); 00088 else endWrite(); 00089 } 00090 00091 XrdXrootdAio *getAio(); 00092 00093 inline XrdXrootdAio *Pop() {XrdXrootdAio *aiop = aioDone; 00094 aioDone = aiop->Next; return aiop; 00095 } 00096 00097 inline void Push(XrdXrootdAio *newp) 00098 {newp->Next = aioDone; aioDone = newp;} 00099 00100 static void Init(int iosize, int maxaiopr, int maxaio=-80); 00101 00102 int Read(); 00103 00104 void Recycle(int deref=1, XrdXrootdAio *aiop=0); 00105 00106 int Write(XrdXrootdAio *aiop); 00107 00108 XrdXrootdAioReq() : XrdJob("aio request") {} 00109 ~XrdXrootdAioReq() {} // Never called 00110 00111 private: 00112 00113 void Clear(XrdLink *lnkp); 00114 00115 static XrdXrootdAioReq *addBlock(); 00116 void endRead(); 00117 void endWrite(); 00118 inline void Lock() {aioMutex.Lock(); isLocked = 1;} 00119 void Scuttle(const char *opname); 00120 void sendError(char *tident); 00121 inline void UnLock() {isLocked = 0; aioMutex.UnLock();} 00122 00123 static const char *TraceID; 00124 static XrdSysError *eDest; // -> Error Object 00125 static XrdSysMutex rqMutex; // Locks static data 00126 static XrdXrootdAioReq *rqFirst; // -> Object in free queue 00127 static int QuantumMin; // aio segment size (Quantum/2) 00128 static int Quantum; // aio segment size 00129 static int QuantumMax; // aio segment size (Quantum*2) 00130 static int maxAioPR; // aio objects per request (max) 00131 static int maxAioPR2; // aio objects per request (max*2) 00132 00133 XrdSysMutex aioMutex; // Locks private data 00134 XrdXrootdAioReq *Next; // -> Chain pointer 00135 00136 off_t myOffset; // Next offset (used for read's only) 00137 int myIOLen; // Size remaining (read and write end) 00138 unsigned int Instance; // Network Link Instance 00139 XrdLink *Link; // -> Network link 00140 XrdXrootdFile *myFile; // -> Associated file 00141 00142 XrdXrootdAio *aioDone; // Next aiocb that completed 00143 XrdXrootdAio *aioFree; // Next aiocb that we can use 00144 int numActive; // Number of aio requests outstanding 00145 int aioTotal; // Actual number of disk bytes transferred 00146 int aioError; // First errno encounetered 00147 char aioType; // 'r' or 'w' or 's' 00148 char respDone; // 1 -> Response has been sent 00149 char isLocked; // 1 -> Object lock being held 00150 char reDrive; // 1 -> Link redrive is needed 00151 00152 XrdXrootdResponse Response; // Copy of the original response object 00153 }; 00154 #endif