XRootD
XrdOfsCksFile Class Reference

#include <XrdOfsCksFile.hh>

+ Inheritance diagram for XrdOfsCksFile:
+ Collaboration diagram for XrdOfsCksFile:

Public Member Functions

 XrdOfsCksFile (const char *tid, const char *path, XrdOssDF *df, XrdCksCalc *cP, bool &delFlag)
 
virtual ~XrdOfsCksFile ()
 
int Close (long long *retsz=0) override
 
int Ftruncate (unsigned long long flen) override
 
int Open (const char *path, int Oflag, mode_t Mode, XrdOucEnv &env) override
 
ssize_t pgWrite (void *buffer, off_t offset, size_t wrlen, uint32_t *csvec, uint64_t opts) override
 
int pgWrite (XrdSfsAio *aioparm, uint64_t opts) override
 
ssize_t Write (const void *buffer, off_t offset, size_t size) override
 
int Write (XrdSfsAio *aiop) override
 
ssize_t WriteV (XrdOucIOVec *writeV, int wrvcnt) override
 
- Public Member Functions inherited from XrdOssWrapDF
 XrdOssWrapDF (XrdOssDF &df2Wrap)
 
virtual ~XrdOssWrapDF ()
 
virtual int Clone (const std::vector< XrdOucCloneSeg > &cVec)
 
virtual int Clone (XrdOssDF &srcFile)
 
uint16_t DFType ()
 
virtual int Fchmod (mode_t mode)
 
virtual int Fctl (int cmd, int alen, const char *args, char **resp=0)
 
virtual void Flush ()
 Flush filesystem cached pages for this file (used for checksums). More...
 
virtual int Fstat (struct stat *buf)
 
virtual int Fsync ()
 
virtual int Fsync (XrdSfsAio *aiop)
 
virtual bool getErrMsg (std::string &eText)
 
virtual int getFD ()
 
virtual off_t getMmap (void **addr)
 
virtual const char * getTID ()
 
virtual int isCompressed (char *cxidp=0)
 
virtual int Opendir (const char *path, XrdOucEnv &env)
 
virtual ssize_t pgRead (void *buffer, off_t offset, size_t rdlen, uint32_t *csvec, uint64_t opts)
 
virtual int pgRead (XrdSfsAio *aioparm, uint64_t opts)
 
virtual ssize_t Read (off_t offset, size_t size)
 
virtual ssize_t Read (void *buffer, off_t offset, size_t size)
 
virtual ssize_t Read (XrdOucRangeList &rlist)
 
virtual int Read (XrdSfsAio *aiop)
 
virtual int Readdir (char *buff, int blen)
 
virtual ssize_t ReadRaw (void *buffer, off_t offset, size_t size)
 
virtual ssize_t ReadV (XrdOucIOVec *readV, int rdvcnt)
 
virtual int StatRet (struct stat *Stat)
 
- Public Member Functions inherited from XrdOssDF
 XrdOssDF (const char *tid="", uint16_t dftype=0, int fdnum=-1)
 
virtual ~XrdOssDF ()
 
uint16_t DFType ()
 

Static Public Member Functions

static void Init (XrdCks *cp, XrdOucEnv *ep)
 
static void setRDSZ (int sz)
 

Additional Inherited Members

- Static Public Attributes inherited from XrdOssDF
static const uint16_t DF_isDir = 0x0001
 Object is for a directory. More...
 
static const uint16_t DF_isFile = 0x0002
 Object is for a file. More...
 
static const uint16_t DF_isProxy = 0x0010
 Object is a proxy object. More...
 
static const uint64_t doCalc = 0x4000000000000000ULL
 pgw: Calculate checksums More...
 
static const int Fctl_ckpObj = 0
 
static const int Fctl_QFinfo = 3
 
static const int Fctl_setFD = 2
 
static const int Fctl_utimes = 1
 
static const uint64_t Verify = 0x8000000000000000ULL
 all: Verify checksums More...
 
- Protected Attributes inherited from XrdOssWrapDF
XrdOssDFwrapDF
 
- Protected Attributes inherited from XrdOssDF
uint16_t dfType
 
int fd
 
off_t pgwEOF
 
short rsvd
 
const char * tident
 

Detailed Description

Definition at line 45 of file XrdOfsCksFile.hh.

Constructor & Destructor Documentation

◆ XrdOfsCksFile()

XrdOfsCksFile::XrdOfsCksFile ( const char *  tid,
const char *  path,
XrdOssDF df,
XrdCksCalc cP,
bool &  delFlag 
)

Definition at line 59 of file XrdOfsCksFile.cc.

61  : XrdOssWrapDF(*df),
62  tident(tid), fPath(strdup(path)), ossDF(df),
63  calcP(cP), altcP(0), viaDel(delF), nextOff(0),
64  ioBuff(0)
65 {
66 // Obtain information about the chacksum we are to use. It should have been
67 // pre-screened for viability, but we check it again just to make sure and
68 // to setup the proper execution path.
69 //
70  int rc, sz;
71  char eBuff[128];
72 
73 // Set the name and get the size of the checksum
74 //
75  cksName = cP->Type(sz);
76  Dirty = false;
77 
78 
79 // Determine how we will compute the real-time checksum. It will either be
80 // either combinable via a re-read computation.
81 //
82  if (cP->Combinable() && (sz == (int)sizeof(uint32_t)))
83  {ProcessRTC = &XrdOfsCksFile::RTC_CB32;
84  altcP = calcP->New();
85  } else {
86  ProcessRTC = &XrdOfsCksFile::RTC_NCXX;
87  if ((rc = posix_memalign(&ioBuff, 4096, ioBlen)))
88  {snprintf(eBuff, sizeof(eBuff),
89  "get buffer for real-time %s checksum for", cksName);
90  eLog.Emsg("ckscon", rc, eBuff, path);
91  Dirty = true;
92  }
93  }
94 }
virtual bool Combinable()
Definition: XrdCksCalc.hh:67
virtual const char * Type(int &csSize)=0
virtual XrdCksCalc * New()=0
XrdOssWrapDF(XrdOssDF &df2Wrap)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:116
XrdSysError * eLog

References XrdCksCalc::Combinable(), XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdCksCalc::New(), and XrdCksCalc::Type().

+ Here is the call graph for this function:

◆ ~XrdOfsCksFile()

XrdOfsCksFile::~XrdOfsCksFile ( )
virtual

Definition at line 100 of file XrdOfsCksFile.cc.

101 {
102 // Cleanup
103 //
104  if (ossDF) delete ossDF;
105  if (calcP) calcP->Recycle();
106  if (altcP) altcP->Recycle();
107  if (fPath) free(fPath);
108  if (ioBuff) free(ioBuff);
109 }
virtual void Recycle()
Recycle the checksum object as it is no longer needed. A default is given.
Definition: XrdCksCalc.hh:145

References XrdCksCalc::Recycle().

+ Here is the call graph for this function:

Member Function Documentation

◆ Close()

int XrdOfsCksFile::Close ( long long *  retsz = 0)
overridevirtual

Close file.

Parameters
retszIf not nil, where the size of the file is to be returned.
Returns
0 upon success or -errno or -osserr (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 122 of file XrdOfsCksFile.cc.

123 {
124  XrdCksData cksData;
125  struct stat Stat;
126  int csSize, rc;;
127 
128 // Process checksum if it is valid
129 //
130  cksMtx.Lock();
131  while(!Dirty) // This is not a loop but avoids deeply next if's.
132  {char eBuff[256];
133 
134  // If we are here vecause of a delete, skip setting checksum
135  //
136  if (viaDel)
137  {snprintf(eBuff, sizeof(eBuff), "File not properly closed; "
138  "real-time %s checksum was not set for", cksName);
139  eLog.Emsg("ckscls", eBuff, fPath);
140  break;
141  }
142 
143  // Verify that checksum was fully calculated
144  //
145 
146  // Verify that all data has been written for this checksum
147  //
148  if (segMap.size())
149  {auto it = segMap.begin();
150  snprintf(eBuff, sizeof(eBuff),
151  "%lld bytes missing at offset %lld; real-time %s",
152  (long long)(it->second.segBeg - nextOff),
153  (long long)nextOff, cksName);
154  eLog.Emsg("ckcls", eBuff, "checksum was not set for", fPath);
155  break;
156  }
157 
158  // Fill out the checksum information
159  //
160  memset((void*)&cksData, 0, sizeof(cksData));
161  cksData.Set(calcP->Type(csSize));
162  cksData.Length = csSize;
163  memcpy(cksData.Value, calcP->Final(), csSize);
164 
165  if ((rc = ossDF->Fstat(&Stat)))
166  {eLog.Emsg("clscls", rc, "get real-time checksum mtime for", fPath);
167  break;
168  }
169 
170  cksData.fmTime = static_cast<long long>(Stat.st_mtime);
171  cksData.csTime = static_cast<int>(time(0) - Stat.st_mtime);
172 
173  if ((rc = cksP->Set(fPath, cksData, 1)))
174  eLog.Emsg("ckscls", rc, "set real-time checksum for", fPath);
175 
176  break;
177  }
178 
179 // Issue close to the underlying object
180 //
181  Dirty = true; // Prevent re-entry processing
182  cksMtx.UnLock();
183  return wrapDF.Close(retsz);
184 }
struct stat Stat
Definition: XrdCks.cc:49
#define stat(a, b)
Definition: XrdPosix.hh:105
virtual char * Final()=0
virtual int Fstat(struct stat *buf)
Definition: XrdOss.hh:164
virtual int Close(long long *retsz=0)=0
XrdOssDF & wrapDF

References XrdOssDF::Close(), XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdCksCalc::Final(), XrdOssDF::Fstat(), XrdSysMutex::Lock(), Stat, stat, XrdCksCalc::Type(), XrdSysMutex::UnLock(), and XrdOssWrapDF::wrapDF.

+ Here is the call graph for this function:

◆ Ftruncate()

int XrdOfsCksFile::Ftruncate ( unsigned long long  flen)
overridevirtual

Set the size of the associated file.

Parameters
flen- The new size of the file.
Returns
0 upon success or -errno or -osserr (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 196 of file XrdOfsCksFile.cc.

197 {
198 
199 // Execute the truncate
200 //
201  int rc = wrapDF.Ftruncate(flen);
202 
203 // We support streaming checksum only when the truncate makes the file 0 length
204 //
205  if (!Dirty)
206  {if (rc < 0)
207  {eLog.Emsg("ckstrunc", rc, "continue real-time checksum for", fPath);
208  Dirty = true;
209  } else {
210  if (flen)
211  {eLog.Emsg("ckstrunc","Unable to continue real-time checksum for",
212  fPath, "; truncate arg not 0.");
213  Dirty = true;
214  } else {
215  nextOff = 0;
216  segMap.clear();
217  calcP->Init();
218  }
219  }
220  }
221 
222 // All done
223 //
224  return rc;
225 }
virtual void Init()=0
virtual int Ftruncate(unsigned long long flen)
Definition: XrdOss.hh:192

References XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdOssDF::Ftruncate(), XrdCksCalc::Init(), and XrdOssWrapDF::wrapDF.

+ Here is the call graph for this function:

◆ Init()

void XrdOfsCksFile::Init ( XrdCks cp,
XrdOucEnv ep 
)
static

Definition at line 231 of file XrdOfsCksFile.cc.

232 {
233 // Record the checksum manager
234 //
235  cksP = cp;
236 }

◆ Open()

int XrdOfsCksFile::Open ( const char *  path,
int  Oflag,
mode_t  Mode,
XrdOucEnv env 
)
overridevirtual

Open a file.

Parameters
path- Pointer to the path of the file to be opened.
Oflag- Standard open flags.
Mode- File open mode (ignored unless creating a file).
env- Reference to environmental information.
Returns
0 upon success or -errno or -osserr (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 242 of file XrdOfsCksFile.cc.

244 {
245 // Make sure we have a clean setup. If not return an error.
246 //
247  if (Dirty) return -ENOTSUP;
248 
249 // We intercept open because for non-combinable checksums we need to make
250 // sure the file is open in r/w mode. Since we don't support such checksums
251 // yet, the code below is commented out.
252 //
253 /* if (!(calcp->Combinable()))
254  {Oflag &= ~O_ACCMODE;
255  Oflag |= O_RDWR;
256  }
257 */
258 // Issue open and if unsuccessful, mark this as a dirty object
259 //
260  int rc = wrapDF.Open(path, Oflag, Mode, env);
261  if (rc) Dirty = true;
262  return rc;
263 }
int Mode
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
Definition: XrdOss.hh:228

References Mode, XrdOssDF::Open(), and XrdOssWrapDF::wrapDF.

+ Here is the call graph for this function:

◆ pgWrite() [1/2]

ssize_t XrdOfsCksFile::pgWrite ( void *  buffer,
off_t  offset,
size_t  wrlen,
uint32_t *  csvec,
uint64_t  opts 
)
overridevirtual

Write file pages into a file with corresponding checksums.

Parameters
buffer- pointer to buffer containing the bytes to write.
offset- The offset where the write is to start. It must be page aligned.
wrlen- The number of bytes to write. If amount is not an integral number of XrdSys::PageSize bytes, then this must be the last write to the file at or above the offset.
csvec- A vector which contains the corresponding CRC32 checksum for each page. It must be size to wrlen/XrdSys::PageSize + (wrlenXrdSys::PageSize != 0)
opts- Processing options (see above).
Returns
>= 0 The number of bytes written upon success. or -errno or -osserr upon failure. (see XrdOssError.hh).
< 0 -errno or -osserr upon failure. (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 269 of file XrdOfsCksFile.cc.

274 {
275  const char* eText;
276 
277 // We will only continue the checksum if the underlying write succeeds
278 //
279  ssize_t retval = wrapDF.pgWrite(buffer, offset, wrlen, csvec, opts);
280 
281 // Continue the streaming checksum if at all possible
282 //
283  if (!Dirty)
284  {if (retval < 0)
285  {eLog.Emsg("ckspgw", retval, "continue real-time checksum for",fPath);
286  Dirty = true;
287  } else {
288  if ((eText = (this->*ProcessRTC)(buffer, offset, wrlen)))
289  {eLog.Emsg("ckspgw","unable to continue real-time checksum for",
290  fPath, eText);
291  }
292  }
293  }
294 
295 // Return actual result
296 //
297  return retval;
298 }
struct myOpts opts
virtual ssize_t pgWrite(void *buffer, off_t offset, size_t wrlen, uint32_t *csvec, uint64_t opts)
Definition: XrdOss.cc:198

References XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), opts, XrdOssDF::pgWrite(), and XrdOssWrapDF::wrapDF.

+ Here is the call graph for this function:

◆ pgWrite() [2/2]

int XrdOfsCksFile::pgWrite ( XrdSfsAio aioparm,
uint64_t  opts 
)
overridevirtual

Write file pages and checksums using asynchronous I/O.

Parameters
aioparm- Pointer to async I/O object controlling the I/O.
opts- Processing options (see above).
Returns
0 upon if request started success or -errno or -osserr (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 302 of file XrdOfsCksFile.cc.

303 {
304  const char* eText;
305 
306 // It is too complicated to do the async I/O before doing the checksum
307 //
308  if (!Dirty)
309  {if ((eText = (this->*ProcessRTC)((void *)aioparm->sfsAio.aio_buf,
310  (off_t) aioparm->sfsAio.aio_offset,
311  (size_t)aioparm->sfsAio.aio_nbytes)))
312  {eLog.Emsg("cksaiopw", "Unable to continue real-time checksum for",
313  fPath, eText);
314  Dirty = true;
315  }
316  }
317 
318 // Now do the I/O
319 //
320  return wrapDF.pgWrite(aioparm, opts);
321 }
off_t aio_offset
Definition: XrdSfsAio.hh:49
size_t aio_nbytes
Definition: XrdSfsAio.hh:48
void * aio_buf
Definition: XrdSfsAio.hh:47
struct aiocb sfsAio
Definition: XrdSfsAio.hh:62

References aiocb::aio_buf, aiocb::aio_nbytes, aiocb::aio_offset, XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), opts, XrdOssDF::pgWrite(), XrdSfsAio::sfsAio, and XrdOssWrapDF::wrapDF.

+ Here is the call graph for this function:

◆ setRDSZ()

static void XrdOfsCksFile::setRDSZ ( int  sz)
inlinestatic

Definition at line 134 of file XrdOfsCksFile.hh.

134  {sz = ((sz/65536) + (sz%65536 != 0)) * 65536;
135  if (sz > 2*1024*1024) ioBlen = 2*1024*1024;
136  else ioBlen = sz;
137  }

◆ Write() [1/2]

ssize_t XrdOfsCksFile::Write ( const void *  buffer,
off_t  offset,
size_t  size 
)
overridevirtual

Write file bytes from a buffer.

Parameters
buffer- pointer to buffer where the bytes reside.
offset- The offset where the write is to start.
size- The number of bytes to write.
Returns
>= 0 The number of bytes that were written.
< 0 -errno or -osserr upon failure (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 338 of file XrdOfsCksFile.cc.

339 {
340  const char* eText;
341 
342 // We will only continue the checksum if the underlying write succeeds
343 //
344  ssize_t retval = wrapDF.Write(buff, offset, blen);
345 
346 // Continue the streaming checksum if at all possible
347 //
348  if (!Dirty)
349  {if (retval < 0)
350  {eLog.Emsg("cksw", retval, "continue streaming checksum for", fPath);
351  Dirty = true;
352  } else {
353  if ((eText = (this->*ProcessRTC)(buff, offset, blen)))
354  {eLog.Emsg("cksw", "Unable to continue real-time checksum for",
355  fPath, eText);
356  Dirty = true;
357  }
358  }
359  }
360 
361 // Return actual result
362 //
363  return retval;
364 }
virtual ssize_t Write(const void *buffer, off_t offset, size_t size)
Definition: XrdOss.hh:385

References XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdOssWrapDF::wrapDF, and XrdOssDF::Write().

+ Here is the call graph for this function:

◆ Write() [2/2]

int XrdOfsCksFile::Write ( XrdSfsAio aiop)
overridevirtual

Write file bytes using asynchronous I/O.

Parameters
aiop- Pointer to async I/O object controlling the I/O.
Returns
0 upon if request started success or -errno or -osserr (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 368 of file XrdOfsCksFile.cc.

369 {
370  const char* eText;
371 
372 // It is too complicated to do the async I/O before doing the checksum
373 //
374  if (!Dirty)
375  {if ((eText = (this->*ProcessRTC)((void *)aioparm->sfsAio.aio_buf,
376  (off_t) aioparm->sfsAio.aio_offset,
377  (size_t)aioparm->sfsAio.aio_nbytes)))
378  {eLog.Emsg("cksaiopw", "Unable to continue real-time checksum for",
379  fPath, eText);
380  Dirty = true;
381  }
382  }
383 
384 // Now do the I/O
385 //
386  return wrapDF.Write(aioparm);
387 }

References aiocb::aio_buf, aiocb::aio_nbytes, aiocb::aio_offset, XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdSfsAio::sfsAio, XrdOssWrapDF::wrapDF, and XrdOssDF::Write().

+ Here is the call graph for this function:

◆ WriteV()

ssize_t XrdOfsCksFile::WriteV ( XrdOucIOVec writeV,
int  wrvcnt 
)
overridevirtual

Write file bytes as directed by the write vector.

Parameters
writeVpointer to the array of write requests.
wrvcntthe number of elements in writeV.
Returns
>=0 The numbe of bytes read.
< 0 -errno or -osserr upon failure (see XrdOssError.hh).

Reimplemented from XrdOssWrapDF.

Definition at line 393 of file XrdOfsCksFile.cc.

394 {
395 
396 // We do not support streaming checksums when WriteV is used
397 //
398  if (!Dirty)
399  {eLog.Emsg("ckswv", "Unable to continue streaming checksum for",
400  fPath, "; WriteV() conflict.");
401  Dirty = true;
402  }
403 
404 // We still handle the actual write
405 //
406  return wrapDF.WriteV(writeV, n);
407 }
virtual ssize_t WriteV(XrdOucIOVec *writeV, int wrvcnt)
Definition: XrdOss.cc:273

References XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdOssWrapDF::wrapDF, and XrdOssDF::WriteV().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: