xrootd
Loading...
Searching...
No Matches
XrdOucCache.hh
Go to the documentation of this file.
1#ifndef __XRDOUCCACHE_HH__
2#define __XRDOUCCACHE_HH__
3/******************************************************************************/
4/* */
5/* X r d O u c C a c h e . 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#include <cerrno>
34#include <cstdint>
35#include <vector>
36
38#include "XrdOuc/XrdOucIOVec.hh"
39
40struct stat;
41class XrdOucEnv;
42
43/******************************************************************************/
44/* X r d O u c C a c h e I O C B */
45/******************************************************************************/
46
47//-----------------------------------------------------------------------------
50//-----------------------------------------------------------------------------
51
53{
54public:
55
56//------------------------------------------------------------------------------
62//------------------------------------------------------------------------------
63virtual
64void Done(int result) = 0;
65
67virtual ~XrdOucCacheIOCB() {}
68};
69
70/******************************************************************************/
71/* X r d O u c C a c h e I O C D */
72/******************************************************************************/
73
74//-----------------------------------------------------------------------------
79//-----------------------------------------------------------------------------
80
82{
83public:
84
85//------------------------------------------------------------------------------
87//------------------------------------------------------------------------------
88virtual
89void DetachDone() = 0;
90
92virtual ~XrdOucCacheIOCD() {}
93};
94
95/******************************************************************************/
96/* C l a s s X r d O u c C a c h e I O */
97/******************************************************************************/
98
99//------------------------------------------------------------------------------
102//------------------------------------------------------------------------------
103
105{
106public:
107
108//------------------------------------------------------------------------------
123//------------------------------------------------------------------------------
124
125virtual bool Detach(XrdOucCacheIOCD &iocd) = 0;
126
127//------------------------------------------------------------------------------
131//------------------------------------------------------------------------------
132virtual
133long long FSize() = 0;
134
135//------------------------------------------------------------------------------
146//------------------------------------------------------------------------------
147
148virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;}
149
150//-----------------------------------------------------------------------------
159//-----------------------------------------------------------------------------
160virtual
161const char *Location(bool refresh=false) {(void)refresh; return "";}
162
163//------------------------------------------------------------------------------
167//------------------------------------------------------------------------------
168virtual
169const char *Path() = 0;
170
171//-----------------------------------------------------------------------------
186//-----------------------------------------------------------------------------
187
188static const uint64_t forceCS = 0x0000000000000001ULL;
189
190virtual int pgRead(char *buff,
191 long long offs,
192 int rdlen,
193 std::vector<uint32_t> &csvec,
194 uint64_t opts=0,
195 int *csfix=0);
196
197//-----------------------------------------------------------------------------
212//-----------------------------------------------------------------------------
213
214virtual void pgRead(XrdOucCacheIOCB &iocb,
215 char *buff,
216 long long offs,
217 int rdlen,
218 std::vector<uint32_t> &csvec,
219 uint64_t opts=0,
220 int *csfix=0)
221 {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts, csfix));}
222
223//-----------------------------------------------------------------------------
237//-----------------------------------------------------------------------------
238
239virtual int pgWrite(char *buff,
240 long long offs,
241 int wrlen,
242 std::vector<uint32_t> &csvec,
243 uint64_t opts=0,
244 int *csfix=0);
245
246//-----------------------------------------------------------------------------
260//-----------------------------------------------------------------------------
261
262virtual void pgWrite(XrdOucCacheIOCB &iocb,
263 char *buff,
264 long long offs,
265 int wrlen,
266 std::vector<uint32_t> &csvec,
267 uint64_t opts=0,
268 int *csfix=0)
269 {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts, csfix));}
270
271//------------------------------------------------------------------------------
277//------------------------------------------------------------------------------
278
279static const int SingleUse = 0x0001;
280
281virtual void Preread(long long offs, int rlen, int opts=0)
282 {(void)offs; (void)rlen; (void)opts;}
283
284//-----------------------------------------------------------------------------
288//-----------------------------------------------------------------------------
289
291 {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
292 int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
294 short minPages; // If rdln/pgsz < min, preread minPages (0->off)
295 signed
296 char minPerf; // Minimum auto preread performance required (0->n/a)
298 void *Reserve3;
299
301 minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
302 };
303
304virtual void Preread(aprParms &Parms) { (void)Parms; }
305
306//------------------------------------------------------------------------------
316//------------------------------------------------------------------------------
317
318virtual int Read (char *buff, long long offs, int rlen) = 0;
319
320//------------------------------------------------------------------------------
331//------------------------------------------------------------------------------
332
333virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
334 {iocb.Done(Read(buff, offs, rlen));}
335
336//------------------------------------------------------------------------------
344//------------------------------------------------------------------------------
345
346virtual int ReadV(const XrdOucIOVec *readV, int rnum);
347
348//------------------------------------------------------------------------------
357//------------------------------------------------------------------------------
358
359virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
360 {iocb.Done(ReadV(readV, rnum));}
361
362//------------------------------------------------------------------------------
367//------------------------------------------------------------------------------
368
369virtual int Sync() = 0;
370
371//------------------------------------------------------------------------------
378//------------------------------------------------------------------------------
379
380virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
381
382//------------------------------------------------------------------------------
389//------------------------------------------------------------------------------
390
391virtual int Trunc(long long offs) = 0;
392
393//------------------------------------------------------------------------------
401//------------------------------------------------------------------------------
402
403virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
404 {iocb.Done(Trunc(offs));}
405
406//------------------------------------------------------------------------------
416//------------------------------------------------------------------------------
417
418virtual void Update(XrdOucCacheIO &iocp) {}
419
420//------------------------------------------------------------------------------
430//------------------------------------------------------------------------------
431
432virtual int Write(char *buff, long long offs, int wlen) = 0;
433
434//------------------------------------------------------------------------------
445//------------------------------------------------------------------------------
446
447virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
448 {iocb.Done(Write(buff, offs, wlen));}
449
450//------------------------------------------------------------------------------
458//------------------------------------------------------------------------------
459
460virtual int WriteV(const XrdOucIOVec *writV, int wnum);
461
462//------------------------------------------------------------------------------
471//------------------------------------------------------------------------------
472
473virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
474 {iocb.Done(WriteV(writV, wnum));}
475
476//------------------------------------------------------------------------------
478//------------------------------------------------------------------------------
479
481protected:
482virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
483};
484
485/******************************************************************************/
486/* C l a s s X r d O u c C a c h e */
487/******************************************************************************/
488
489//------------------------------------------------------------------------------
492//------------------------------------------------------------------------------
493
495{
496public:
497
498//------------------------------------------------------------------------------
514//------------------------------------------------------------------------------
515
516static const int optFIS = 0x0001;
517static const int optRW = 0x0004;
518static const int optNEW = 0x0014;
519static const int optWIN = 0x0024;
520
521virtual
522XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int opts=0) = 0;
523
524//------------------------------------------------------------------------------
568//------------------------------------------------------------------------------
569
571
572virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
573 LFP_Reason why=ForAccess, bool forall=false)
574 {(void)url; (void)buff; (void)blen; (void)why;
575 (void)forall;
576 if (buff && blen > 0) *buff = 0;
577 return -ENOTSUP;
578 }
579
580//------------------------------------------------------------------------------
595//------------------------------------------------------------------------------
596
597virtual int Prepare(const char *url, int oflags, mode_t mode)
598 {(void)url; (void)oflags; (void)mode; return 0;}
599
600//------------------------------------------------------------------------------
608//------------------------------------------------------------------------------
609
610virtual int Rename(const char* oldp, const char* newp)
611 {(void)oldp; (void)newp; return 0;}
612
613//------------------------------------------------------------------------------
620//------------------------------------------------------------------------------
621
622virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
623
624//------------------------------------------------------------------------------
636//------------------------------------------------------------------------------
637
638virtual int Stat(const char *url, struct stat &sbuff)
639 {(void)url; (void)sbuff; return 1;}
640
641//------------------------------------------------------------------------------
649//------------------------------------------------------------------------------
650
651virtual int Truncate(const char* path, off_t size)
652 {(void)path; (void)size; return 0;}
653
654//------------------------------------------------------------------------------
661//------------------------------------------------------------------------------
662
663virtual int Unlink(const char* path) {(void)path; return 0;}
664
665//------------------------------------------------------------------------------
674//------------------------------------------------------------------------------
675
676enum XeqCmd {xeqNoop = 0};
677
678virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
679 {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
680
681//------------------------------------------------------------------------------
684//------------------------------------------------------------------------------
685
687
688//------------------------------------------------------------------------------
690//------------------------------------------------------------------------------
691
692const char CacheType[8];
693
694//------------------------------------------------------------------------------
698//------------------------------------------------------------------------------
699
700 XrdOucCache(const char *ctype) : CacheType{}
701// : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
702 {strncpy(const_cast<char *>(CacheType), ctype,
703 sizeof(CacheType));
704 const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
705 }
706
707//------------------------------------------------------------------------------
709//------------------------------------------------------------------------------
710
711virtual ~XrdOucCache() {}
712};
713
714/******************************************************************************/
715/* C r e a t i n g C a c h e P l u g - I n s */
716/******************************************************************************/
717
718//------------------------------------------------------------------------------
750
751//------------------------------------------------------------------------------
756//------------------------------------------------------------------------------
757
765typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *Logger, const char *Config,
766 const char *Parms, XrdOucEnv *envP);
767
768#endif
#define stat(a, b)
Definition XrdPosix.hh:96
Definition XrdOucCache.hh:53
virtual void Done(int result)=0
XrdOucCacheIOCB()
Definition XrdOucCache.hh:66
virtual ~XrdOucCacheIOCB()
Definition XrdOucCache.hh:67
Definition XrdOucCache.hh:82
XrdOucCacheIOCD()
Definition XrdOucCache.hh:91
virtual ~XrdOucCacheIOCD()
Definition XrdOucCache.hh:92
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
Definition XrdOucCache.hh:105
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
virtual int Read(char *buff, long long offs, int rlen)=0
virtual int Fstat(struct stat &sbuff)
Definition XrdOucCache.hh:148
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int Write(char *buff, long long offs, int wlen)=0
virtual void Update(XrdOucCacheIO &iocp)
Definition XrdOucCache.hh:418
virtual int Sync()=0
static const int SingleUse
Mark pages for single use.
Definition XrdOucCache.hh:279
static const uint64_t forceCS
Definition XrdOucCache.hh:188
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition XrdOucCache.hh:403
virtual void Preread(long long offs, int rlen, int opts=0)
Definition XrdOucCache.hh:281
virtual long long FSize()=0
virtual void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
Definition XrdOucCache.hh:214
virtual const char * Path()=0
virtual void Preread(aprParms &Parms)
Definition XrdOucCache.hh:304
virtual ~XrdOucCacheIO()
Definition XrdOucCache.hh:482
virtual const char * Location(bool refresh=false)
Definition XrdOucCache.hh:161
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition XrdOucCache.hh:473
virtual void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
Definition XrdOucCache.hh:262
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition XrdOucCache.hh:380
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition XrdOucCache.hh:333
virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
Definition XrdOucCache.hh:447
XrdOucCacheIO()
Construct and Destructor.
Definition XrdOucCache.hh:480
virtual int Trunc(long long offs)=0
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
Definition XrdOucCache.hh:359
Definition XrdOucCacheStats.hh:44
Definition XrdOucCache.hh:495
virtual int Rename(const char *oldp, const char *newp)
Definition XrdOucCache.hh:610
virtual int Stat(const char *url, struct stat &sbuff)
Definition XrdOucCache.hh:638
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int opts=0)=0
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition XrdOucCache.hh:692
static const int optRW
File is read/write (o/w read/only)
Definition XrdOucCache.hh:517
virtual int Truncate(const char *path, off_t size)
Definition XrdOucCache.hh:651
XeqCmd
Definition XrdOucCache.hh:676
@ xeqNoop
Definition XrdOucCache.hh:676
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition XrdOucCache.hh:678
LFP_Reason
Definition XrdOucCache.hh:570
@ ForAccess
Definition XrdOucCache.hh:570
@ ForPath
Definition XrdOucCache.hh:570
@ ForInfo
Definition XrdOucCache.hh:570
virtual ~XrdOucCache()
Destructor.
Definition XrdOucCache.hh:711
virtual int Unlink(const char *path)
Definition XrdOucCache.hh:663
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
Definition XrdOucCache.hh:572
static const int optWIN
File is new -> optRW use write-in cache.
Definition XrdOucCache.hh:519
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition XrdOucCache.hh:597
XrdOucCacheStats Statistics
Definition XrdOucCache.hh:686
XrdOucCache(const char *ctype)
Definition XrdOucCache.hh:700
virtual int Rmdir(const char *dirp)
Definition XrdOucCache.hh:622
static const int optNEW
File is new -> optRW (o/w read or write)
Definition XrdOucCache.hh:518
static const int optFIS
File is structured (e.g. root file)
Definition XrdOucCache.hh:516
Definition XrdOucEnv.hh:42
Definition XrdSysLogger.hh:53
Definition XrdOucCache.hh:291
aprParms()
Definition XrdOucCache.hh:300
short minPages
Definition XrdOucCache.hh:294
signed char minPerf
Definition XrdOucCache.hh:296
int prRecalc
Definition XrdOucCache.hh:292
int Trigger
Definition XrdOucCache.hh:291
int Reserve1
Definition XrdOucCache.hh:293
void * Reserve3
Definition XrdOucCache.hh:298
char Reserve2
Definition XrdOucCache.hh:297
Definition XrdOucIOVec.hh:41