XRootD
XrdRmcData.hh
Go to the documentation of this file.
1 #ifndef __XRDRMCDATA_HH__
2 #define __XRDRMCDATA_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d R m c D a t a . h h */
6 /* */
7 /* (c) 2019 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 /* The XrdRmcData object defines a remanufactured XrdOucCacheIO object and
34  is used to front a XrdOucCacheIO object with an XrdRmcReal object.
35 */
36 
37 #include "XrdOuc/XrdOucCache.hh"
38 #include "XrdRmc/XrdRmcReal.hh"
39 #include "XrdSys/XrdSysPthread.hh"
40 #include "XrdSys/XrdSysXSLock.hh"
41 
42 class XrdRmcData : public XrdOucCacheIO
43 {
44 public:
46 
47 bool Detach(XrdOucCacheIOCD &iocd);
48 
49 long long FSize() {return (ioObj ? ioObj->FSize() : 0);}
50 
51 const char *Path() {return ioObj->Path();}
52 
53 void Preread();
54 
55 void Preread(aprParms &Parms);
56 
57 void Preread(long long Offs, int rLen, int Opts=0);
58 
59 int Read (char *Buffer, long long Offset, int Length);
60 
61 static int setAPR(aprParms &Dest, aprParms &Src, int pSize);
62 
63 int Sync() {return 0;} // We only support write-through for now
64 
65 int Trunc(long long Offset);
66 
67 int Write(char *Buffer, long long Offset, int Length);
68 
70  long long vn, int opts);
71 
72 private:
73  ~XrdRmcData() {}
74 void QueuePR(long long SegOffs, int rLen, int prHow, int isAuto=0);
75 int Read (XrdOucCacheStats &Now,
76  char *Buffer, long long Offs, int Length);
77 
79 
80 // The following is for read/write support
81 //
82 class MrSw
83 {
84 public:
85 inline void UnLock() {if (myLock) {myLock->UnLock(myUsage); myLock = 0;}}
86 
87  MrSw(XrdSysXSLock *lP, XrdSysXS_Type usage) : myUsage(usage)
88  {if ((myLock = lP)) lP->Lock(usage);}
89  ~MrSw() {if (myLock) myLock->UnLock(myUsage);}
90 
91 private:
92 XrdSysXSLock *myLock;
93 XrdSysXS_Type myUsage;
94 };
95 
96 // Statics per connection
97 //
98 XrdOucCacheStats Statistics;
99 
100 // The following supports MRSW serialization
101 //
102 XrdSysXSLock rwLock;
103 XrdSysXSLock *pPLock; // 0 if no preread lock required
104 XrdSysXSLock *rPLock; // 0 if no read lock required
105 XrdSysXSLock *wPLock; // 0 if no write lock required
106 XrdSysXS_Type pPLopt;
107 XrdSysXS_Type rPLopt;
108 
109 XrdSysMutex DMutex;
110 XrdRmcReal *Cache;
111 XrdOucCacheIO *ioObj;
112 long long VNum;
113 long long SegSize;
114 long long OffMask;
115 long long SegShft;
116 int maxCache;
117 char isFIS;
118 char isRW;
119 char Debug;
120 
121 static const int okRW = 1;
122 static const int xqRW = 2;
123 
124 // Preread Control Area
125 //
126 XrdRmcReal::prTask prReq;
127 XrdSysSemaphore *prStop;
128 
129 long long prNSS; // Next Sequential Segment for maxi prereads
130 
131 static const int prRRMax= 5;
132 long long prRR[prRRMax]; // Recent reads
133 int prRRNow; // Pointer to next entry to use
134 
135 static const int prMax = 8;
136 static const int prRun = 1; // Status in prActive (running)
137 static const int prWait = 2; // Status in prActive (waiting)
138 
139 static const int prLRU = 1; // Status in prOpt (set LRU)
140 static const int prSUSE = 2; // Status in prOpt (set Single Use)
141 static const int prSKIP = 3; // Status in prOpt (skip entry)
142 
143 aprParms Apr;
144 long long prCalc;
145 long long prBeg[prMax];
146 long long prEnd[prMax];
147 int prNext;
148 int prFree;
149 int prPerf;
150 char prOpt[prMax];
151 char prOK;
152 char prActive;
153 char prAuto;
154 };
155 #endif
void usage()
struct myOpts opts
XrdSysXS_Type
Definition: XrdSysXSLock.hh:38
virtual const char * Path()=0
virtual int Read(char *buff, long long offs, int rlen)=0
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:308
virtual long long FSize()=0
int Read(char *Buffer, long long Offset, int Length)
Definition: XrdRmcData.cc:337
void Preread()
Definition: XrdRmcData.cc:155
int Trunc(long long Offset)
Definition: XrdRmcData.cc:514
XrdRmcData(XrdRmcReal *cP, XrdOucCacheIO *ioP, long long vn, int opts)
Definition: XrdRmcData.cc:42
const char * Path()
Definition: XrdRmcData.hh:51
long long FSize()
Definition: XrdRmcData.hh:49
int Write(char *Buffer, long long Offset, int Length)
Definition: XrdRmcData.cc:536
bool Detach(XrdOucCacheIOCD &iocd)
Definition: XrdRmcData.cc:97
int Sync()
Definition: XrdRmcData.hh:63
static int setAPR(aprParms &Dest, aprParms &Src, int pSize)
Definition: XrdRmcData.cc:489
void Lock(const XrdSysXS_Type usage)
Definition: XrdSysXSLock.cc:55
int Opts
Definition: XrdMpxStats.cc:58