XRootD
Loading...
Searching...
No Matches
XrdOfsChkPnt Class Reference

#include <XrdOfsChkPnt.hh>

+ Inheritance diagram for XrdOfsChkPnt:
+ Collaboration diagram for XrdOfsChkPnt:

Public Member Functions

 XrdOfsChkPnt (XrdOssDF &ossfl, const char *lfn, const char *ckpfn=0)
 
virtual ~XrdOfsChkPnt ()
 
int Create ()
 
int Delete ()
 
void Finished ()
 
int Query (struct iov &range)
 
int Restore (bool *readok=0)
 
int Truncate (struct iov *&range)
 
int Write (struct iov *&range, int rnum)
 
- Public Member Functions inherited from XrdOucChkPnt
 XrdOucChkPnt ()
 Constructor and destructor.
 
virtual ~XrdOucChkPnt ()
 
virtual int Create ()=0
 
virtual int Delete ()=0
 
virtual void Finished ()=0
 
virtual int Query (struct iov &range)=0
 
virtual int Restore (bool *readok=0)=0
 
virtual int Truncate (struct iov *&range)=0
 
virtual int Write (struct iov *&range, int rnum)=0
 

Detailed Description

Definition at line 43 of file XrdOfsChkPnt.hh.

Constructor & Destructor Documentation

◆ XrdOfsChkPnt()

XrdOfsChkPnt::XrdOfsChkPnt ( XrdOssDF ossfl,
const char *  lfn,
const char *  ckpfn = 0 
)
inline

Constructor and destructor.

Parameters
ossfl- reference to the Oss File Object for the source file.
lfn- pointer to the source file path.
ckpfn- pointer to optional prexisting checkpoint file.

Definition at line 122 of file XrdOfsChkPnt.hh.

123 : lFN(lfn), cpFile(ckpfn), ossFile(ossfl), fSize(0),
124 cpUsed(0) {}

◆ ~XrdOfsChkPnt()

virtual XrdOfsChkPnt::~XrdOfsChkPnt ( )
inlinevirtual

Definition at line 126 of file XrdOfsChkPnt.hh.

126{}

Member Function Documentation

◆ Create()

int XrdOfsChkPnt::Create ( )
virtual

Create a checkpoint.

Returns
0 upon success and -errno upon failure.

Implements XrdOucChkPnt.

Definition at line 81 of file XrdOfsChkPnt.cc.

82{
83 struct stat Stat;
84 int rc;
85
86// Make sure we don't have a checkpoint outstanding
87//
88 if (cpFile.isActive()) return -EEXIST;
89
90// Get the file size
91//
92 if ((rc = ossFile.Fstat(&Stat))) return rc;
93 fSize = Stat.st_size;
94
95// Create the actual checkpoint
96//
97 if ((rc = cpFile.Create(lFN, Stat)))
98 OfsEroute.Emsg("ChkPnt", rc, "create checkpoint for", lFN);
99
100// Return result
101//
102 OfsEroute.Emsg("ChkPnt", cpFile.FName(true), "checkpoint created for", lFN);
103 return rc;
104}
struct stat Stat
Definition XrdCks.cc:49
XrdSysError OfsEroute(0)
#define stat(a, b)
Definition XrdPosix.hh:96
int Create(const char *lfn, struct stat &Stat)
const char * FName(bool trim=false)
virtual int Fstat(struct stat *buf)
Definition XrdOss.hh:136
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References XrdOfsCPFile::Create(), XrdSysError::Emsg(), XrdOfsCPFile::FName(), XrdOssDF::Fstat(), XrdOfsCPFile::isActive(), OfsEroute, Stat, and stat.

+ Here is the call graph for this function:

◆ Delete()

int XrdOfsChkPnt::Delete ( )
virtual

Delete a checkpoint.

Returns
0 upon success and -errno upon failure.

Implements XrdOucChkPnt.

Definition at line 110 of file XrdOfsChkPnt.cc.

111{
112 int rc = 0;
113
114// Delete the checkpoint file if we have one
115//
116 if (cpFile.isActive() && (rc = cpFile.Destroy()))
117 OfsEroute.Emsg("ChkPnt", rc, "delete checkpoint", cpFile.FName());
118
119// All done
120//
121 return rc;
122}

References XrdOfsCPFile::Destroy(), XrdSysError::Emsg(), XrdOfsCPFile::FName(), XrdOfsCPFile::isActive(), and OfsEroute.

Referenced by Restore().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Finished()

void XrdOfsChkPnt::Finished ( )
inlinevirtual

Indicate that the checkpointing is finished. Any outstanding checkpoint should be delete and the object should delete itself if necessary.

Implements XrdOucChkPnt.

Definition at line 68 of file XrdOfsChkPnt.hh.

68{delete this;}

◆ Query()

int XrdOfsChkPnt::Query ( struct iov range)
virtual

Query checkpoint limits.

Parameters
range- reference to where limits are placed. range.length - holds maximum checkpoint length allowed.
Returns
0 upon success and -errno upon failure.

Implements XrdOucChkPnt.

Definition at line 169 of file XrdOfsChkPnt.cc.

170{
171 range.offset = cpUsed;
173 return 0;
174}
static long long MaxSZ
long long offset

References XrdOfsConfigCP::MaxSZ, XrdOucIOVec::offset, and XrdOucIOVec::size.

◆ Restore()

int XrdOfsChkPnt::Restore ( bool *  readok = 0)
virtual

Restore a checkpoint.

Parameters
readok- When not nil and an error occurs readok is set true if read access is still allowed; otherwise no access should be allowed.
Returns
0 upon success and -errno upon failure.

Implements XrdOucChkPnt.

Definition at line 180 of file XrdOfsChkPnt.cc.

181{
182 cUp cup;
184 const char *eWhy = 0;
185 int rc;
186
187// Make sure we have a checkpoint to restore
188//
189 if (!cpFile.isActive()) return -ENOENT;
190
191// Get the checkpoint information
192//
193 if ((rc = cpFile.RestoreInfo(rinfo, eWhy)))
194 {if (rc == -ENODATA) {Delete(); return 0;}
195 XrdOucString eMsg(256);
196 eMsg = "process chkpnt (";
197 if (eWhy) eMsg.append(eWhy);
198 eMsg.append(')');
199 OfsEroute.Emsg("ChkPnt", rc, eMsg.c_str(), cpFile.FName());
200 lFN = rinfo.srcLFN;
201 return Failed(0, rc, readok);
202 }
203
204
205// If we don't have a filename then we neeed to open it
206//
207 if (!lFN)
208 {XrdOucEnv ckpEnv;
209 lFN = rinfo.srcLFN;
210 rc = ossFile.Open(lFN, O_RDWR, 0, ckpEnv);
211 if (rc) return Failed("open", rc, readok);
212 cup.ossP = &ossFile;
213 }
214
215// Truncate the file to its original size
216//
217 rc = ossFile.Ftruncate(rinfo.fSize);
218 if (rc) return Failed("truncate", rc, readok);
219
220// Write back the original contents of the file. It might not have any.
221//
222 if (rinfo.DataVec)
223 {rc = ossFile.WriteV(rinfo.DataVec, rinfo.DataNum);
224 if (rc != rinfo.DataLen)
225 return Failed("write", (rc < 0 ? rc : -EIO), readok);
226 }
227
228// Sync the data to disk
229//
230 ossFile.Fsync();
231
232// Set file modification time to the original value.
233//
234 struct timeval utArg[2];
235 utArg[0].tv_sec = utArg[1].tv_sec = rinfo.mTime;
236 utArg[0].tv_usec = utArg[1].tv_usec = 0;
237 rc = ossFile.Fctl(XrdOssDF::Fctl_utimes, sizeof(utArg), (const char *)&utArg);
238 if (rc && rc != -ENOTSUP) OfsEroute.Emsg("ChkPnt", rc, "set mtime for", lFN);
239
240// Now we can delete the checkpoint record
241//
242 if ((rc = Delete()))
243 {OfsEroute.Emsg("ChkPnt", rc, "delete chkpnt", cpFile.FName());
244 return Failed(0, rc, readok);
245 }
246
247// All done
248//
249 OfsEroute.Emsg("ChkPnt", lFN, "successfully restored.");
250 return 0;
251}
#define ENODATA
#define eMsg(x)
int64_t fSize
Original size of the source file.
const char * srcLFN
Pointer to the source filename.
XrdOucIOVec * DataVec
A vector of data that must be written back.
int DataLen
Number of bytes to write back (may be 0)
int DataNum
Number of elements in DataVec (may be 0)
time_t mTime
Original modification time of the source.
int RestoreInfo(rInfo &rinfo, const char *&ewhy)
virtual int Fsync()
Definition XrdOss.hh:144
virtual ssize_t WriteV(XrdOucIOVec *writeV, int wrvcnt)
Definition XrdOss.cc:257
virtual int Ftruncate(unsigned long long flen)
Definition XrdOss.hh:164
static const int Fctl_utimes
Definition XrdOss.hh:416
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
Definition XrdOss.hh:200
virtual int Fctl(int cmd, int alen, const char *args, char **resp=0)
Definition XrdOss.cc:150

References XrdOfsCPFile::rInfo::DataLen, XrdOfsCPFile::rInfo::DataNum, XrdOfsCPFile::rInfo::DataVec, Delete(), XrdSysError::Emsg(), eMsg, ENODATA, XrdOssDF::Fctl(), XrdOssDF::Fctl_utimes, XrdOfsCPFile::FName(), XrdOfsCPFile::rInfo::fSize, XrdOssDF::Fsync(), XrdOssDF::Ftruncate(), XrdOfsCPFile::isActive(), XrdOfsCPFile::rInfo::mTime, OfsEroute, XrdOssDF::Open(), XrdOfsCPFile::RestoreInfo(), XrdOfsCPFile::rInfo::srcLFN, and XrdOssDF::WriteV().

+ Here is the call graph for this function:

◆ Truncate()

int XrdOfsChkPnt::Truncate ( struct iov *&  range)
virtual

Truncate a file to a specific size.

Parameters
range- reference to the file truncate size in offset.
Returns
0 upon success and -errno upon failure.

Implements XrdOucChkPnt.

Definition at line 257 of file XrdOfsChkPnt.cc.

258{
259 cUp cup;
260 int rc, dlen;
261
262// Make sure we have a checkpoint active
263//
264 if (!cpFile.isActive()) return -ENOENT;
265
266// Make sure offset is not negative
267//
268 if (range[0].offset < 0) return -EINVAL;
269
270// Check if we really need to do something here
271//
272 if (range[0].offset >= fSize) return 0;
273
274// Compute size to save and whether we will exceed our quota
275//
276 dlen = fSize - range[0].offset;
277 if (dlen + cpUsed > XrdOfsConfigCP::MaxSZ) return -EDQUOT;
278
279// Reserve space for all this data
280//
281 if (!cpFile.Reserve(dlen, 1)) return -ENOSPC;
282 cpUsed += dlen;
283
284// Allocate a buffer to read in the data
285//
286 if (!(cup.buff = (char *)malloc(dlen))) return -ENOMEM;
287
288// Perform checkpoint
289//
290 rc = ossFile.Read(cup.buff, range[0].offset, dlen);
291 if (rc < 0 || (rc && (rc = cpFile.Append(cup.buff, range[0].offset, rc))))
292 return rc;
293
294// Set new file size as it s now smaller
295//
296
297// Make sure all of it gets on media
298//
299 if (!(rc = cpFile.Sync())) fSize = range[0].offset;
300 return rc;
301}
bool Reserve(int dlen, int nseg)
int Append(const char *data, off_t offset, int dlen)
virtual ssize_t Read(off_t offset, size_t size)
Definition XrdOss.hh:281

References XrdOfsCPFile::Append(), XrdOfsCPFile::isActive(), XrdOfsConfigCP::MaxSZ, XrdOucIOVec::offset, XrdOssDF::Read(), XrdOfsCPFile::Reserve(), and XrdOfsCPFile::Sync().

+ Here is the call graph for this function:

◆ Write()

int XrdOfsChkPnt::Write ( struct iov *&  range,
int  rnum 
)
virtual

Write data to a checkpointed file.

Parameters
range- reference to the file pieces to write.
rnum- number of elements in "range".
Returns
0 upon success and -errno upon failure.

Implements XrdOucChkPnt.

Definition at line 307 of file XrdOfsChkPnt.cc.

308{
309 cUp cup;
310 int rc, dlen = 0, buffSZ = 0, numVS = 0, totSZ = 0;
311
312// Make sure we have a checkpoint active
313//
314 if (!cpFile.isActive()) return -ENOENT;
315
316// Run through the write vector computing what to checkpoint
317//
318 for (int i = 0; i < rnum; i++)
319 {if (range[i].offset < 0) return -EINVAL;
320 if (range[i].offset < fSize && range[i].size)
321 {if (range[i].size + range[i].offset < fSize) dlen = range[i].size;
322 else dlen = fSize - range[i].offset;
323 if (dlen > XrdOfsConfigCP::MaxSZ) return -EDQUOT;
324 if (dlen > buffSZ) buffSZ = dlen;
325 range[i].info = dlen; totSZ += dlen; numVS++;
326 } else range[i].info = 0;
327 }
328
329// If nothing to checkpoint, simply return
330//
331 if (!buffSZ) return 0;
332
333// Check if we will exceed our quota with this checkpoint
334//
335 if (dlen + cpUsed > XrdOfsConfigCP::MaxSZ) return -EDQUOT;
336
337// Allocate a buffer to read in the data
338//
339 if (!(cup.buff = (char *)malloc(buffSZ))) return -ENOMEM;
340
341// Reserve space for all this data
342//
343 if (!cpFile.Reserve(dlen, numVS)) return -ENOSPC;
344 cpUsed += dlen;
345
346// Perform checkpoint
347//
348 for (int i = 0; i < rnum; i++)
349 {if (range[i].info)
350 {rc = ossFile.Read(cup.buff, range[i].offset, range[i].info);
351 if (rc < 0
352 || (rc && (rc = cpFile.Append(cup.buff, range[i].offset, rc))))
353 return rc;
354 }
355 }
356
357// Make sure all of it gets on media
358//
359 return cpFile.Sync();
360}

References XrdOfsCPFile::Append(), XrdOucIOVec::info, XrdOfsCPFile::isActive(), XrdOfsConfigCP::MaxSZ, XrdOucIOVec::offset, XrdOssDF::Read(), XrdOfsCPFile::Reserve(), XrdOucIOVec::size, and XrdOfsCPFile::Sync().

+ Here is the call graph for this function:

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