xrootd
XrdXrootdAio.hh
Go to the documentation of this file.
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-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include "XProtocol/XPtypes.hh"
00034 #include "XrdSys/XrdSysPthread.hh"
00035 #include "XrdSfs/XrdSfsAio.hh"
00036 #include "Xrd/XrdScheduler.hh"
00037 #include "XrdXrootd/XrdXrootdResponse.hh"
00038 
00039 /******************************************************************************/
00040 /*                          X r d X r o o t d A i o                           */
00041 /******************************************************************************/
00042 
00043 // The XrdXrootdAio object represents a single aio read or write operation. One
00044 // or more of these are allocated to the XrdXrootdAioReq and passed as upcast
00045 // arguments to the sfs file object to effect asynchronous I/O.
00046 
00047 class XrdBuffer;
00048 class XrdBuffManager;
00049 class XrdSysError;
00050 class XrdXrootdAioReq;
00051 class XrdXrootdStats;
00052   
00053 class XrdXrootdAio : public XrdSfsAio
00054 {
00055 friend class XrdXrootdAioReq;
00056 public:
00057         XrdBuffer    *buffp;   // -> Buffer object
00058 
00059 virtual void          doneRead();
00060 
00061 virtual void          doneWrite();
00062 
00063 virtual void          Recycle();
00064 
00065 
00066               XrdXrootdAio() {Next=0; aioReq=0; buffp=0;}
00067              ~XrdXrootdAio() {};
00068 
00069 private:
00070 
00071 static  XrdXrootdAio    *Alloc(XrdXrootdAioReq *arp, int bsize=0);
00072 static  XrdXrootdAio    *addBlock();
00073 
00074 static  const char      *TraceID;
00075 static  XrdBuffManager  *BPool;   // -> Buffer Manager
00076 static  XrdScheduler    *Sched;   // -> System Scheduler
00077 static  XrdXrootdStats  *SI;      // -> System Statistics
00078 static  XrdSysMutex      fqMutex; // Locks static data
00079 static  XrdXrootdAio    *fqFirst; // -> Object in free queue
00080 static  int              maxAio;  // Maximum Aio objects we can yet have
00081 
00082         XrdXrootdAio    *Next;    // Chain pointer
00083         XrdXrootdAioReq *aioReq;  // -> Associated request object
00084 };
00085 
00086 /******************************************************************************/
00087 /*                       X r d X r o o t d A i o R e q                        */
00088 /******************************************************************************/
00089 
00090 // The XrdXrootdAioReq object represents a complete aio request. It handles
00091 // the appropriate translation of the synchrnous request to an async one,
00092 // provides the redrive logic, and handles ending status.
00093 //
00094 class XrdLink;
00095 class XrdXrootdFile;
00096 class XrdXrootdProtocol;
00097   
00098 class XrdXrootdAioReq : public XrdJob
00099 {
00100 friend class XrdXrootdAio;
00101 public:
00102 
00103 static XrdXrootdAioReq   *Alloc(XrdXrootdProtocol *p, char iot, int numaio=0);
00104 
00105        void               DoIt() {if (aioType == 'r') endRead();
00106                                      else endWrite();
00107                                  }
00108 
00109        XrdXrootdAio      *getAio();
00110 
00111 inline XrdXrootdAio      *Pop() {XrdXrootdAio *aiop = aioDone;
00112                                  aioDone = aiop->Next; return aiop;
00113                                 }
00114 
00115 inline void               Push(XrdXrootdAio *newp)
00116                               {newp->Next = aioDone; aioDone = newp;}
00117 
00118 static void               Init(int iosize, int maxaiopr, int maxaio=-80);
00119 
00120        int                Read();
00121 
00122        void               Recycle(int deref=1, XrdXrootdAio *aiop=0);
00123 
00124        int                Write(XrdXrootdAio *aiop);
00125 
00126        XrdXrootdAioReq() : XrdJob("aio request") {}
00127       ~XrdXrootdAioReq() {} // Never called
00128 
00129 private:
00130 
00131         void               Clear(XrdLink *lnkp);
00132 
00133 static  XrdXrootdAioReq   *addBlock();
00134         void               endRead();
00135         void               endWrite();
00136 inline  void               Lock() {aioMutex.Lock(); isLocked = 1;}
00137         void               Scuttle(const char *opname);
00138         void               sendError(char *tident);
00139 inline  void               UnLock() {isLocked = 0; aioMutex.UnLock();}
00140 
00141 static  const char        *TraceID;
00142 static  XrdSysError       *eDest;      // -> Error Object
00143 static  XrdSysMutex        rqMutex;    // Locks static data
00144 static  XrdXrootdAioReq   *rqFirst;    // -> Object in free queue
00145 static  int                QuantumMin; // aio segment size (Quantum/2)
00146 static  int                Quantum;    // aio segment size
00147 static  int                QuantumMax; // aio segment size (Quantum*2)
00148 static  int                maxAioPR;   // aio objects per request (max)
00149 static  int                maxAioPR2;  // aio objects per request (max*2)
00150 
00151         XrdSysMutex        aioMutex;  // Locks private data
00152         XrdXrootdAioReq   *Next;      // -> Chain pointer
00153 
00154         off_t              myOffset;  // Next offset    (used for read's only)
00155         int                myIOLen;   // Size remaining (read and write end)
00156         unsigned int       Instance;  //    Network Link Instance
00157         XrdLink           *Link;      // -> Network link
00158         XrdXrootdFile     *myFile;    // -> Associated file
00159 
00160         XrdXrootdAio      *aioDone;   // Next aiocb that completed
00161         XrdXrootdAio      *aioFree;   // Next aiocb that we can use
00162         int                numActive; // Number of aio requests outstanding
00163         int                aioTotal;  // Actual number of disk bytes transferred
00164         int                aioError;  // First errno encounetered
00165         char               aioType;   // 'r' or 'w' or 's'
00166         char               respDone;  // 1 -> Response has been sent
00167         char               isLocked;  // 1 -> Object lock being held
00168         char               reDrive;   // 1 -> Link redrive is needed
00169 
00170         XrdXrootdResponse  Response;  // Copy of the original response object
00171 };
00172 #endif